Skip to content

Commit

Permalink
Never duplicate script with Resource.duplicate()
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickeon committed Oct 22, 2022
1 parent 276ab5b commit 1450441
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/io/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
}
Variant p = get(E.name);

if (E.name == "script") {
r->set(E.name, p); // Do not ever duplicate Script property.
continue;
}

if ((p.get_type() == Variant::DICTIONARY || p.get_type() == Variant::ARRAY)) {
r->set(E.name, p.duplicate(p_subresources));
} else if (p.get_type() == Variant::OBJECT && (p_subresources || (E.usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE))) {
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Resource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<param index="0" name="subresources" type="bool" default="false" />
<description>
Duplicates this resource, returning a new resource with its [code]export[/code]ed or [constant PROPERTY_USAGE_STORAGE] properties copied from the original.
If [param subresources] is [code]false[/code], a shallow copy is returned. Nested resources within subresources are not duplicated and are shared from the original resource. This behavior can be overriden by the [constant PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE] flag.
If [param subresources] is [code]false[/code], a shallow copy is returned. Nested resources within subresources are not duplicated and are shared from the original resource. This behavior can be overriden by the [constant PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE] flag. The resource's [code]script[/code] is [b]always[/b] shared.
[b]Note:[/b] For custom resources, this method will fail if [method Object._init] has been defined with required parameters.
</description>
</method>
Expand Down

0 comments on commit 1450441

Please sign in to comment.