diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml
index 271b7fa4375..aece3c75a67 100644
--- a/doc/classes/Node.xml
+++ b/doc/classes/Node.xml
@@ -282,6 +282,7 @@
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.
[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].
+ [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].
@@ -1381,6 +1382,16 @@
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.
+
+ Duplicate also non-serializable variables (i.e. without [constant @GlobalScope.PROPERTY_USAGE_STORAGE]).
+
+
+ Duplicate using default flags. This constant is useful to add or remove a single flag.
+ [codeblock]
+ # Duplicate non-exported variables.
+ var dupe = duplicate(DUPLICATE_DEFAULT | DUPLICATE_INTERNAL_STATE)
+ [/codeblock]
+
The node will not be internal.
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 1f9d5d94b8d..bc98af836d0 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -3060,7 +3060,7 @@ void Node::_duplicate_properties(const Node *p_root, const Node *p_original, Nod
p_original->get_property_list(&props);
const StringName &script_property_name = CoreStringName(script);
for (const PropertyInfo &E : props) {
- if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
+ if (!(p_flags & DUPLICATE_INTERNAL_STATE) && !(E.usage & PROPERTY_USAGE_STORAGE)) {
continue;
}
const StringName name = E.name;
@@ -3840,7 +3840,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tree"), &Node::get_tree);
ClassDB::bind_method(D_METHOD("create_tween"), &Node::create_tween);
- ClassDB::bind_method(D_METHOD("duplicate", "flags"), &Node::duplicate, DEFVAL(DUPLICATE_USE_INSTANTIATION | DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS));
+ ClassDB::bind_method(D_METHOD("duplicate", "flags"), &Node::duplicate, DEFVAL(DUPLICATE_DEFAULT));
ClassDB::bind_method(D_METHOD("replace_by", "node", "keep_groups"), &Node::replace_by, DEFVAL(false));
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() {
BIND_ENUM_CONSTANT(DUPLICATE_GROUPS);
BIND_ENUM_CONSTANT(DUPLICATE_SCRIPTS);
BIND_ENUM_CONSTANT(DUPLICATE_USE_INSTANTIATION);
+ BIND_ENUM_CONSTANT(DUPLICATE_INTERNAL_STATE);
+ BIND_ENUM_CONSTANT(DUPLICATE_DEFAULT);
BIND_ENUM_CONSTANT(INTERNAL_MODE_DISABLED);
BIND_ENUM_CONSTANT(INTERNAL_MODE_FRONT);
diff --git a/scene/main/node.h b/scene/main/node.h
index 2d0bea16079..cb9b5d5c226 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -103,8 +103,10 @@ public:
DUPLICATE_GROUPS = 2,
DUPLICATE_SCRIPTS = 4,
DUPLICATE_USE_INSTANTIATION = 8,
+ DUPLICATE_INTERNAL_STATE = 16,
+ DUPLICATE_DEFAULT = DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS | DUPLICATE_USE_INSTANTIATION,
#ifdef TOOLS_ENABLED
- DUPLICATE_FROM_EDITOR = 16,
+ DUPLICATE_FROM_EDITOR = 32,
#endif
};