2929/* *************************************************************************/
3030
3131#include " node.h"
32- #include " node.compat.inc"
3332
3433#include " core/config/project_settings.h"
3534#include " core/core_string_names.h"
@@ -3006,7 +3005,7 @@ static void find_owned_by(Node *p_by, Node *p_node, List<Node *> *p_owned) {
30063005 }
30073006}
30083007
3009- void Node::replace_by (Node *p_node, bool p_keep_groups, bool p_keep_children ) {
3008+ void Node::replace_by (Node *p_node, bool p_keep_groups) {
30103009 ERR_THREAD_GUARD
30113010 ERR_FAIL_NULL (p_node);
30123011 ERR_FAIL_COND (p_node->data .parent );
@@ -3027,13 +3026,13 @@ void Node::replace_by(Node *p_node, bool p_keep_groups, bool p_keep_children) {
30273026 _replace_connections_target (p_node);
30283027
30293028 if (data.owner ) {
3030- if (p_keep_children) {
3031- for (int i = 0 ; i < get_child_count (); i++) {
3032- find_owned_by (data.owner , get_child (i), &owned_by_owner);
3033- }
3029+ for (int i = 0 ; i < get_child_count (); i++) {
3030+ find_owned_by (data.owner , get_child (i), &owned_by_owner);
30343031 }
3032+
30353033 _clean_up_owner ();
30363034 }
3035+
30373036 Node *parent = data.parent ;
30383037 int index_in_parent = get_index (false );
30393038
@@ -3045,33 +3044,31 @@ void Node::replace_by(Node *p_node, bool p_keep_groups, bool p_keep_children) {
30453044
30463045 emit_signal (SNAME (" replacing_by" ), p_node);
30473046
3048- if (p_keep_children) {
3049- while (get_child_count ()) {
3050- Node *child = get_child (0 );
3051- remove_child (child);
3052- if (!child->is_owned_by_parent ()) {
3053- // add the custom children to the p_node
3054- Node *child_owner = child->get_owner () == this ? p_node : child->get_owner ();
3055- child->set_owner (nullptr );
3056- p_node->add_child (child);
3057- child->set_owner (child_owner);
3058- }
3047+ while (get_child_count ()) {
3048+ Node *child = get_child (0 );
3049+ remove_child (child);
3050+ if (!child->is_owned_by_parent ()) {
3051+ // add the custom children to the p_node
3052+ Node *child_owner = child->get_owner () == this ? p_node : child->get_owner ();
3053+ child->set_owner (nullptr );
3054+ p_node->add_child (child);
3055+ child->set_owner (child_owner);
30593056 }
3057+ }
30603058
3061- for (Node *E : owned) {
3062- if (E-> data . owner != p_node ) {
3063- E->set_owner ( p_node);
3064- }
3059+ p_node-> set_owner (owner);
3060+ for (Node *E : owned ) {
3061+ if ( E->data . owner != p_node) {
3062+ E-> set_owner (p_node);
30653063 }
3064+ }
30663065
3067- for (Node *E : owned_by_owner) {
3068- if (E->data .owner != owner) {
3069- E->set_owner (owner);
3070- }
3066+ for (Node *E : owned_by_owner) {
3067+ if (E->data .owner != owner) {
3068+ E->set_owner (owner);
30713069 }
30723070 }
30733071
3074- p_node->set_owner (owner);
30753072 p_node->set_scene_file_path (get_scene_file_path ());
30763073}
30773074
@@ -3598,7 +3595,7 @@ void Node::_bind_methods() {
35983595 ClassDB::bind_method (D_METHOD (" create_tween" ), &Node::create_tween);
35993596
36003597 ClassDB::bind_method (D_METHOD (" duplicate" , " flags" ), &Node::duplicate, DEFVAL (DUPLICATE_USE_INSTANTIATION | DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS));
3601- ClassDB::bind_method (D_METHOD (" replace_by" , " node" , " keep_groups" , " keep_children " ), &Node::replace_by, DEFVAL (false ), DEFVAL ( true ));
3598+ ClassDB::bind_method (D_METHOD (" replace_by" , " node" , " keep_groups" ), &Node::replace_by, DEFVAL (false ));
36023599
36033600 ClassDB::bind_method (D_METHOD (" set_scene_instance_load_placeholder" , " load_placeholder" ), &Node::set_scene_instance_load_placeholder);
36043601 ClassDB::bind_method (D_METHOD (" get_scene_instance_load_placeholder" ), &Node::get_scene_instance_load_placeholder);
0 commit comments