+1 vote

I'd like to know how to hide a node with a button? I'm basically a beginner, and there are almost no tutorials, so...anyway, I'd like an example script, and I'm wondering if the same code would also work for an ogg. sound file. If not, a script for that would help too. Many thanks!

in Engine by (27 points)

1 Answer

+2 votes

You mean that you want to hide for example a Sprite when clicking a button?
Then, i assume you have this tree structure:

Main (Node2D)

Then you can use the signal pressed() and connect it to a function on Main.gd script (can connect it via editor. Go to Node tab, select pressed() signal and click connect). The function created when you connect the signal via editor should look like this:

func _on_Button_pressed():

Is that what you need?

P.S: you can also hide Node2D and anything that derives from it. And what do you mean by hiding a sound file? stopping it from beeing played?

by (3,503 points)

Oh, I think I see what's wrong here. Wow. Anyway, this has taken a lot longer than it probably should have, and I feel stupid...but I think the problem was I didn't attach the script to the main scene. How would I do that?

You just need to select the root node from tha main scene and click the add script button in the editor. Have you already completed the official "Your first game" tutorial? If not, i recommend you doing it step by step, it shows all basic concepts in an easy way.

did you get it working?

Yes! It works now. Sorry, I just went to sleep for the night. But yeah, it works great, the weird thing is that I just fiddled around with it, and ended up changing it back to what you said and now suddenly it works. I must have changed something without realizing it. But anyway, thank you! I appreciate it!

You are welcome! Glad to help. If it worked fine, you may selec the answer so others see its solved.

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.