-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting scene unique node from subscene's root fails/succeeds if subscene has any/no unique nodes itself #66536
Comments
According to #60298 (comment), this is intended and should be documented.
|
@timothyqiu Note that the quoted explanation is not what actually happens, it currently behaves like:
Which suggests the current implementation doesn't match the original intent. |
But docs says that you can't access unique nodes outside of the scene https://docs.godotengine.org/en/stable/tutorials/scripting/scene_unique_nodes.html#same-scene-limitation |
The problem is that the scene root is the only node in the scene that is not owned by the scene root. Obvious algorithm:
The only question is how to distinguish the scene root from the non-scene root (all scenes are inserted into a single tree). There is |
I would like to have an opportunity to get unique nodes outside of the scene. It looks beautiful. Using the group for only one element looks like a dirty hack |
So why the unique nodes should be restricted to their scene? Why not to allow global access? |
I think you'll get all kinds of trouble if global access is allowed. e.g. If both Scene A and Scene B contains a unique node named |
@dalexeev The issue with such approach is it could be considered limiting. The subscene's root is at the same:
then referring to So it would fail even though
@dalexeev Because of the above I'd say this question is irrelevant (hence this answer too). Nevertheless, currently checking Line 2434 in c3e512e
so seems like that's the way to go in case such check is needed. What I'm suggesting is making the behavior consistent. Basically changing the current behavior which is (#66536 (comment)):
by removing the (2.) from the list above so it would become:
which #60298 (comment) originally suggested. And of course ensuring it's explained clearly in the docs that for a subscene's root node the unique name is firstly searched in the subscene's unique names, and if not found in the the "outer" scene's unique names. Codewise: diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 264a152392..bddb45f2d6 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -1568,22 +1568,14 @@ Node *Node::get_node_or_null(const NodePath &p_path) const {
}
} else if (name.is_node_unique_name()) {
- if (current->data.owned_unique_nodes.size()) {
- // Has unique nodes in ownership
- Node **unique = current->data.owned_unique_nodes.getptr(name);
- if (!unique) {
- return nullptr;
- }
- next = *unique;
- } else if (current->data.owner) {
- Node **unique = current->data.owner->data.owned_unique_nodes.getptr(name);
- if (!unique) {
- return nullptr;
- }
- next = *unique;
- } else {
+ Node **unique = current->data.owned_unique_nodes.getptr(name);
+ if (!unique && current->data.owner) {
+ unique = current->data.owner->data.owned_unique_nodes.getptr(name);
+ }
+ if (!unique) {
return nullptr;
}
+ next = *unique;
} else {
next = nullptr; |
If would be great if we can get the ability to access unique from both scene and subscene. Otherwise it would be good to have the bug fixed. Since it can get difficult for beginners to figure out what went wrong when all their previously working code starts getting null references just because they made a node unique in their scene/subscene. |
Turns out it was an oversight: #89686 (review). 🙃 |
Well. Oversight means it was the intended behavior, but from the present point of view, such behavior is unnecessary. I personally think this is a compat breaking behavior change request rather than a bug. But nevermind 😄 |
Or it means that the behavior in this specific case was not even considered / taken into account. In which case I wouldn't say it was intented (for this specific case). We could ask reduz to clarify his original intentions but I'd guess he doesn't remember it anyway. 😄
And I haven't changed my mind for all this time and still consider it as a bug. Would be surprising to me if someone will report the change from my PR as a regression. Well, we'll see... 👀 |
Godot version
3.5.stable, 4.0.beta1
System information
N/A
Issue description
Currently unique nodes are checked within the owner of the node only if the node have no unique nodes stored itself:
godot/scene/main/node.cpp
Lines 1303 to 1319 in 14e1f36
It results in inconsitence for instanced subscenes as obtaining a unique node within the scene from the root of a subscene can succeed/fail depending on whether the subscene has unique nodes itself. Example:
Test scene:
Subscenes:
Script attached to subscenes:
Output:
Not sure what's the originally intended/desired behavior but obtaining
%UniqueOuter
should fail/succeed consistently for both subscenes' roots.Steps to reproduce
See above example / MRP below.
Minimal reproduction project
subscene_unique_name_bug.zip (3.5)
The text was updated successfully, but these errors were encountered: