Skip to content
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

Closed
OatsProduction opened this issue Dec 20, 2022 · 4 comments · Fixed by godotengine/godot-docs#6670
Closed

C# Error with Unique Node - returns always null #70351

OatsProduction opened this issue Dec 20, 2022 · 4 comments · Fixed by godotengine/godot-docs#6670

Comments

@OatsProduction
Copy link

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

  • Create C# Project
  • Add a "Unique Node"
  • Add a Singelton scene to the project
  • Getting the Unique Node doesn't work anymore and returns null

Link for the minmal project https://github.com/OatsProduction/Godot-unique-node-bug-demo

Minimal reproduction project

Godot-unique-node-bug-demo-main.zip

@raulsntos
Copy link
Member

raulsntos commented Dec 20, 2022

When running the MRP I'm getting this error:

ERROR: System.InvalidCastException: Unable to cast object of type 'Godot.Control' to type 'Hud'.

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:

ERROR: Node not found: "%Hud" (relative to "/root/GlobalScript").

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:
Godot-unique-node-bug-demo-gd.zip

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.

@martinruefenacht
Copy link

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).

@raulsntos
Copy link
Member

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?

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:

@OatsProduction
Copy link
Author

@raulsntos Sorry for the very late answer. This solves the issue for me.
Thank you :)

@github-project-automation github-project-automation bot moved this from To Assess to Done in 4.x Priority Issues Feb 24, 2023
@YuriSizov YuriSizov added this to the 4.0 milestone Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants