-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
C# Error with Unique Node - returns always null #70351
Comments
When running the MRP I'm getting this error:
Looking at the scene Main.tscn, it seems the Hud node does not have the Hud.cs script attached. When the script is attached everything seems to be working correctly, I get:
This is expected because you are trying to access a unique node from a separate scene. Unique nodes are only accessible from the scene they are in because they are only unique in their scene, you can have multiple unique nodes with the same name as long as they are in different scenes. Also note that this is not exclusive to C# but also happens with GDScript. Here's your MRP ported to GDScript: I suppose this could be better documented in https://docs.godotengine.org/en/latest/tutorials/scripting/scene_unique_nodes.html so I'll mark this as a documentation issue. |
I just ran into this issue as well, but I am having it happen when I am trying to access a CharacterBody3D from a Control Node. Is this also intended? This is all in the effort of finding if a player is stationary. I can either deal with non-unique path figuring out or have a unique name that allows me to look up the players state. The work around at the moment is that the CharacterBody3D calls the general group that these nodes are in and informs them that it is moving (not ideal in any sense). |
Whether it's possible to access a node by their unique name or not does not depend on the node type. A scene unique node can only be retrieved by a node inside the same scene. There's a PR that adds more clarification about how scene unique nodes work and should close this issue: godotengine/godot-docs#6670. Please, take a look and let us know if that resolves your questions about how it works. Here's a semi-rendered view of the doc page from the PR: |
@raulsntos Sorry for the very late answer. This solves the issue for me. |
Godot version
4.0 8-Beta
System information
Ubuntu 22
Issue description
I encountered a bug in C#. When I want to get a unique node, the return value is null.
I think this issue has something to do with singleton scenes added to the scene tree.
Steps to reproduce
Link for the minmal project https://github.com/OatsProduction/Godot-unique-node-bug-demo
Minimal reproduction project
Godot-unique-node-bug-demo-main.zip
The text was updated successfully, but these errors were encountered: