Skip to content

Commit faddd60

Browse files
reduzakien-mga
authored andcommitted
Add unique Node IDs to support base and instantiated scene refactorings
The main goal of this PR is to safeguard when a base or instantiated scene changes (nodes renamed, moved or readded), that the hierarchy is still maintained and the node and its overridden properties can be preserved. What it does: * Implements unique node IDs. * These IDs act as a fallback to names when saving. * The IDs are **USED AS A FALLBACK**, so they are just an addition. It should not break any current existing scene. * If a scene renames or moves a node, inherited or instantiated scenes will no longer lose reference to it. Unlike the previous approach, this one is intended to be a fallback, only used if the node is not found. This makes it safer to implement and ensure that, at worst case, we fail to find the node, but nothing breaks.
1 parent 60b7b8b commit faddd60

File tree

6 files changed

+370
-28
lines changed

6 files changed

+370
-28
lines changed

core/io/resource_uid.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ void ResourceUID::clear() {
351351
unique_ids.clear();
352352
changed = false;
353353
}
354+
354355
void ResourceUID::_bind_methods() {
355356
ClassDB::bind_method(D_METHOD("id_to_text", "id"), &ResourceUID::id_to_text);
356357
ClassDB::bind_method(D_METHOD("text_to_id", "text_id"), &ResourceUID::text_to_id);

scene/main/node.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,6 +2082,14 @@ Node *Node::find_parent(const String &p_pattern) const {
20822082
return nullptr;
20832083
}
20842084

2085+
void Node::set_unique_scene_id(int32_t p_unique_id) {
2086+
data.unique_scene_id = p_unique_id;
2087+
}
2088+
2089+
int32_t Node::get_unique_scene_id() const {
2090+
return data.unique_scene_id;
2091+
}
2092+
20852093
Window *Node::get_window() const {
20862094
ERR_THREAD_GUARD_V(nullptr);
20872095
Viewport *vp = get_viewport();

scene/main/node.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class Node : public Object {
132132
#ifdef DEBUG_ENABLED
133133
static SafeNumeric<uint64_t> total_node_count;
134134
#endif
135+
enum {
136+
UNIQUE_SCENE_ID_UNASSIGNED = 0
137+
};
135138

136139
void _update_process(bool p_enable, bool p_for_children);
137140

@@ -281,6 +284,8 @@ class Node : public Object {
281284
mutable bool is_translation_domain_inherited : 1;
282285
mutable bool is_translation_domain_dirty : 1;
283286

287+
int32_t unique_scene_id = UNIQUE_SCENE_ID_UNASSIGNED;
288+
284289
mutable NodePath *path_cache = nullptr;
285290

286291
} data;
@@ -527,6 +532,9 @@ class Node : public Object {
527532
Node *get_parent() const;
528533
Node *find_parent(const String &p_pattern) const;
529534

535+
void set_unique_scene_id(int32_t p_unique_id);
536+
int32_t get_unique_scene_id() const;
537+
530538
Window *get_window() const;
531539
Window *get_non_popup_window() const;
532540
Window *get_last_exclusive_window() const;

0 commit comments

Comments
 (0)