Skip to content

Commit 25f0e0a

Browse files
committed
Add DUPLICATE_INTERNAL_STATE flag
1 parent c6d130a commit 25f0e0a

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
@@ -280,6 +280,7 @@
280280
<description>
281281
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.
282282
[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].
283+
[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].
283284
</description>
284285
</method>
285286
<method name="find_child" qualifiers="const">
@@ -1378,6 +1379,16 @@
13781379
<constant name="DUPLICATE_USE_INSTANTIATION" value="8" enum="DuplicateFlags">
13791380
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.
13801381
</constant>
1382+
<constant name="DUPLICATE_INTERNAL_STATE" value="16" enum="DuplicateFlags">
1383+
Duplicate also non-serializable variables (i.e. without [constant @GlobalScope.PROPERTY_USAGE_STORAGE]).
1384+
</constant>
1385+
<constant name="DUPLICATE_DEFAULT" value="15" enum="DuplicateFlags">
1386+
Duplicate using default flags. This constant is useful to add or remove a single flag.
1387+
[codeblock]
1388+
# Duplicate non-exported variables.
1389+
var dupe = duplicate(DUPLICATE_DEFAULT | DUPLICATE_INTERNAL_STATE)
1390+
[/codeblock]
1391+
</constant>
13811392
<constant name="INTERNAL_MODE_DISABLED" value="0" enum="InternalMode">
13821393
The node will not be internal.
13831394
</constant>

scene/main/node.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,7 +3012,7 @@ void Node::_duplicate_properties(const Node *p_root, const Node *p_original, Nod
30123012
}
30133013
}
30143014
for (const PropertyInfo &E : props) {
3015-
if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
3015+
if (!(p_flags & DUPLICATE_INTERNAL_STATE) && !(E.usage & PROPERTY_USAGE_STORAGE)) {
30163016
continue;
30173017
}
30183018
const StringName name = E.name;
@@ -3800,7 +3800,7 @@ void Node::_bind_methods() {
38003800
ClassDB::bind_method(D_METHOD("get_tree"), &Node::get_tree);
38013801
ClassDB::bind_method(D_METHOD("create_tween"), &Node::create_tween);
38023802

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

38063806
ClassDB::bind_method(D_METHOD("set_scene_instance_load_placeholder", "load_placeholder"), &Node::set_scene_instance_load_placeholder);
@@ -3955,6 +3955,8 @@ void Node::_bind_methods() {
39553955
BIND_ENUM_CONSTANT(DUPLICATE_GROUPS);
39563956
BIND_ENUM_CONSTANT(DUPLICATE_SCRIPTS);
39573957
BIND_ENUM_CONSTANT(DUPLICATE_USE_INSTANTIATION);
3958+
BIND_ENUM_CONSTANT(DUPLICATE_INTERNAL_STATE);
3959+
BIND_ENUM_CONSTANT(DUPLICATE_DEFAULT);
39583960

39593961
BIND_ENUM_CONSTANT(INTERNAL_MODE_DISABLED);
39603962
BIND_ENUM_CONSTANT(INTERNAL_MODE_FRONT);

scene/main/node.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ class Node : public Object {
100100
DUPLICATE_GROUPS = 2,
101101
DUPLICATE_SCRIPTS = 4,
102102
DUPLICATE_USE_INSTANTIATION = 8,
103+
DUPLICATE_INTERNAL_STATE = 16,
104+
DUPLICATE_DEFAULT = DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS | DUPLICATE_USE_INSTANTIATION,
103105
#ifdef TOOLS_ENABLED
104-
DUPLICATE_FROM_EDITOR = 16,
106+
DUPLICATE_FROM_EDITOR = 32,
105107
#endif
106108
};
107109

0 commit comments

Comments
 (0)