Root node of instantiated UI scene is being deemed a null instance

Godot Version

Godot v4.1.2-stable

Question

In my main scene, I instantiated a scene whose root node is a Control node, which I have renamed “Menu”, and, in the ready function of the script that’s attached to the root node of my main scene, I am trying to hide the Control node by calling “$Menu.hide()”. When I run the game, however, I immediately get the following error message: “Attempt to call function ‘hide’ in base ‘null instance’ on a null instance.” I tried making Menu local, but I got the same error, and changing “$Menu.hide()” to “$Menu.visible = false” didn’t work either. I’m not calling queue_free() on it at any point in any of my scripts, so why is it being considered a null instance? Menu is a child of the root node of my main scene that I have instantiated it into, by the way (not a grandchild, or anything like that).

Bit hard to tell from your text. My suspicions always go to the file-like pathing of those node names. Try $“…/Menu” and so on. Also drag and drop $Menu into your code and Godot should fill the path in for u.

Yeah, I think you are probably right about it having something to do with file paths. I ended up preloading the menu node by going like “var menu = preload(“res://Menu.tscn”)” and then instantiating the node via code, and that worked. I know you didn’t say anything about instantiating via code, but you gave me the idea to do so, so, thank you!

1 Like

Happy you fixed it! Good luck.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.