Skip to content

Commit 6a3d1f1

Browse files
committed
Merge pull request #57121 from KoBeWi/noddeganger
Add `DUPLICATE_INTERNAL_STATE` flag
2 parents 5d72153 + 25f0e0a commit 6a3d1f1

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

doc/classes/Node.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@
282282
<description>
283283
Duplicates the node, returning a new node with all of its properties, signals, groups, and children copied from the original. The behavior can be tweaked through the [param flags] (see [enum DuplicateFlags]). Internal nodes are not duplicated.
284284
[b]Note:[/b] For nodes with a [Script] attached, if [method Object._init] has been defined with required parameters, the duplicated node will not have a [Script].
285+
[b]Note:[/b] By default, this method will duplicate only properties marked for serialization (i.e. using [constant @GlobalScope.PROPERTY_USAGE_STORAGE], or in GDScript, [annotation @GDScript.@export]). If you want to duplicate all properties, use [constant DUPLICATE_INTERNAL_STATE].
285286
</description>
286287
</method>
287288
<method name="find_child" qualifiers="const">
@@ -1381,6 +1382,16 @@
13811382
<constant name="DUPLICATE_USE_INSTANTIATION" value="8" enum="DuplicateFlags">
13821383
Duplicate using [method PackedScene.instantiate]. If the node comes from a scene saved on disk, reuses [method PackedScene.instantiate] as the base for the duplicated node and its children.
13831384
</constant>
1385+
<constant name="DUPLICATE_INTERNAL_STATE" value="16" enum="DuplicateFlags">
1386+
Duplicate also non-serializable variables (i.e. without [constant @GlobalScope.PROPERTY_USAGE_STORAGE]).
1387+
</constant>
1388+
<constant name="DUPLICATE_DEFAULT" value="15" enum="DuplicateFlags">
1389+
Duplicate using default flags. This constant is useful to add or remove a single flag.
1390+
[codeblock]
1391+
# Duplicate non-exported variables.
1392+
var dupe = duplicate(DUPLICATE_DEFAULT | DUPLICATE_INTERNAL_STATE)
1393+
[/codeblock]
1394+
</constant>
13841395
<constant name="INTERNAL_MODE_DISABLED" value="0" enum="InternalMode">
13851396
The node will not be internal.
13861397
</constant>

scene/main/node.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,7 +3060,7 @@ void Node::_duplicate_properties(const Node *p_root, const Node *p_original, Nod
30603060
p_original->get_property_list(&props);
30613061
const StringName &script_property_name = CoreStringName(script);
30623062
for (const PropertyInfo &E : props) {
3063-
if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
3063+
if (!(p_flags & DUPLICATE_INTERNAL_STATE) && !(E.usage & PROPERTY_USAGE_STORAGE)) {
30643064
continue;
30653065
}
30663066
const StringName name = E.name;
@@ -3840,7 +3840,7 @@ void Node::_bind_methods() {
38403840
ClassDB::bind_method(D_METHOD("get_tree"), &Node::get_tree);
38413841
ClassDB::bind_method(D_METHOD("create_tween"), &Node::create_tween);
38423842

3843-
ClassDB::bind_method(D_METHOD("duplicate", "flags"), &Node::duplicate, DEFVAL(DUPLICATE_USE_INSTANTIATION | DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS));
3843+
ClassDB::bind_method(D_METHOD("duplicate", "flags"), &Node::duplicate, DEFVAL(DUPLICATE_DEFAULT));
38443844
ClassDB::bind_method(D_METHOD("replace_by", "node", "keep_groups"), &Node::replace_by, DEFVAL(false));
38453845

38463846
ClassDB::bind_method(D_METHOD("set_scene_instance_load_placeholder", "load_placeholder"), &Node::set_scene_instance_load_placeholder);
@@ -3990,6 +3990,8 @@ void Node::_bind_methods() {
39903990
BIND_ENUM_CONSTANT(DUPLICATE_GROUPS);
39913991
BIND_ENUM_CONSTANT(DUPLICATE_SCRIPTS);
39923992
BIND_ENUM_CONSTANT(DUPLICATE_USE_INSTANTIATION);
3993+
BIND_ENUM_CONSTANT(DUPLICATE_INTERNAL_STATE);
3994+
BIND_ENUM_CONSTANT(DUPLICATE_DEFAULT);
39933995

39943996
BIND_ENUM_CONSTANT(INTERNAL_MODE_DISABLED);
39953997
BIND_ENUM_CONSTANT(INTERNAL_MODE_FRONT);

scene/main/node.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ class Node : public Object {
103103
DUPLICATE_GROUPS = 2,
104104
DUPLICATE_SCRIPTS = 4,
105105
DUPLICATE_USE_INSTANTIATION = 8,
106+
DUPLICATE_INTERNAL_STATE = 16,
107+
DUPLICATE_DEFAULT = DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS | DUPLICATE_USE_INSTANTIATION,
106108
#ifdef TOOLS_ENABLED
107-
DUPLICATE_FROM_EDITOR = 16,
109+
DUPLICATE_FROM_EDITOR = 32,
108110
#endif
109111
};
110112

0 commit comments

Comments
 (0)