0 votes

I am trying to hide/show a "Menu" Panel. How the nodes are structures is: Root "World" Node2D then the rest of the nodes are all children of "World." The children are: "Background" Panel, "TextureButton" TextureButton, and "Menu" Panel. I have 2 scripts: 1 attached to the root node and the other script attached to the TextButton.

Under the _ready function in the root node I have get_node("Menu").hide() which successfully hides the panel. For the other script I have get_node("Menu").show() under _pressed, but it is giving the error in the title.

in Engine by (60 points)

1 Answer

+1 vote
Best answer

get_node("Menu") is going to look for a direct child of the node this script is on named "Menu". From your description, it sounds like Menu is a sister to TextureButton, in which case you'd want your get_node() call to go to the parent, then the Menu. get_parent().get_node("Menu") or get_node("../Menu")

Check out the documentation on the get_node() method. It's well-documented with examples, and is an important concept to understand.

by (1,328 points)
selected by

Oh thank you! I don't know why it didn't occur to me to look at documentation first like I usually do.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.