Skip to content

Commit 9c5e968

Browse files
committed
Merge pull request godotengine#90432 from Rindbee/correctly-replace-scene-root-when-must_reload
Correctly replace scene root when `must_reload` in `EditorData::check_and_update_scene()`
2 parents 7d7d303 + 248e5bf commit 9c5e968

File tree

7 files changed

+28
-88
lines changed

7 files changed

+28
-88
lines changed

doc/classes/Node.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,8 @@
795795
<return type="void" />
796796
<param index="0" name="node" type="Node" />
797797
<param index="1" name="keep_groups" type="bool" default="false" />
798-
<param index="2" name="keep_children" type="bool" default="true" />
799798
<description>
800-
Replaces this node by the given [param node]. If [param keep_children] is [code]true[/code] all children of this node are moved to [param node].
799+
Replaces this node by the given [param node]. All children of this node are moved to [param node].
801800
If [param keep_groups] is [code]true[/code], the [param node] is added to the same groups that the replaced node is in (see [method add_to_group]).
802801
[b]Warning:[/b] The replaced node is removed from the tree, but it is [b]not[/b] deleted. To prevent memory leaks, store a reference to the node in a variable, or use [method Object.free].
803802
</description>

editor/editor_data.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,7 @@ bool EditorData::check_and_update_scene(int p_idx) {
722722

723723
new_scene->set_scene_file_path(edited_scene[p_idx].root->get_scene_file_path());
724724
Node *old_root = edited_scene[p_idx].root;
725-
edited_scene.write[p_idx].root = new_scene;
726-
old_root->replace_by(new_scene, false, false);
725+
EditorNode::get_singleton()->set_edited_scene(new_scene);
727726
memdelete(old_root);
728727
edited_scene.write[p_idx].selection = new_selection;
729728

editor/editor_node.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3670,9 +3670,7 @@ void EditorNode::set_edited_scene(Node *p_scene) {
36703670
if (old_edited_scene_root->get_parent() == scene_root) {
36713671
scene_root->remove_child(old_edited_scene_root);
36723672
}
3673-
if (old_edited_scene_root->is_connected("replacing_by", callable_mp(this, &EditorNode::set_edited_scene))) {
3674-
old_edited_scene_root->disconnect(SNAME("replacing_by"), callable_mp(this, &EditorNode::set_edited_scene));
3675-
}
3673+
old_edited_scene_root->disconnect(SNAME("replacing_by"), callable_mp(this, &EditorNode::set_edited_scene));
36763674
}
36773675
get_editor_data().set_edited_scene_root(p_scene);
36783676

misc/extension_api_validation/4.2-stable.expected

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,6 @@ Validate extension JSON: Error: Field 'classes/AcceptDialog/methods/remove_butto
241241
Changed argument type to the more specific one actually expected by the method. Compatibility method registered.
242242

243243

244-
GH-89992
245-
--------
246-
Validate extension JSON: Error: Field 'classes/Node/methods/replace_by/arguments': size changed value in new API, from 2 to 3.
247-
248-
Added optional argument to prevent children to be reparented during replace_by. Compatibility method registered.
249-
250-
251244
GH-88047
252245
--------
253246
Validate extension JSON: Error: Field 'classes/AStar2D/methods/get_id_path/arguments': size changed value in new API, from 2 to 3.

scene/main/node.compat.inc

Lines changed: 0 additions & 41 deletions
This file was deleted.

scene/main/node.cpp

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
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);

scene/main/node.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,6 @@ class Node : public Object {
310310
Variant _call_thread_safe_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
311311

312312
protected:
313-
#ifndef DISABLE_DEPRECATED
314-
void _replace_by_bind_compat_89992(Node *p_node, bool p_keep_data = false);
315-
static void _bind_compatibility_methods();
316-
#endif // DISABLE_DEPRECATED
317-
318313
void _block() { data.blocked++; }
319314
void _unblock() { data.blocked--; }
320315

@@ -634,7 +629,7 @@ class Node : public Object {
634629
return binds;
635630
}
636631

637-
void replace_by(Node *p_node, bool p_keep_groups = false, bool p_keep_children = true);
632+
void replace_by(Node *p_node, bool p_keep_data = false);
638633

639634
void set_process_mode(ProcessMode p_mode);
640635
ProcessMode get_process_mode() const;

0 commit comments

Comments
 (0)