From 1450441befc8ce9688bb3fc461bee2baaa25935d Mon Sep 17 00:00:00 2001 From: Micky Date: Mon, 5 Sep 2022 20:26:16 +0200 Subject: [PATCH] Never duplicate `script` with Resource.`duplicate()` --- core/io/resource.cpp | 5 +++++ doc/classes/Resource.xml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/io/resource.cpp b/core/io/resource.cpp index ab30fb1ca3dd..fba6283789a5 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -260,6 +260,11 @@ Ref 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))) { diff --git a/doc/classes/Resource.xml b/doc/classes/Resource.xml index b2b8a37e3938..be9cc398fcb1 100644 --- a/doc/classes/Resource.xml +++ b/doc/classes/Resource.xml @@ -24,7 +24,7 @@ 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.