The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

This is an issue for a long time,

So in a game I have, I have 2 scenes. In one of the scenes I have multiple buttons that are attached to the same script, and when a button gets pressed I disable it. But if I change a scene and go back the button has been enabled again,

Is there any way to change between scenes and the button staying as it is?

The script also has a timer for when the button should be again enabled, idk if that's gonna be a problem.

Godot version 3.5.1
in Engine by (25 points)

1 Answer

0 votes

You'll want to store the state (enabled / disabled) of each button and restore that state after the scene changes. Since the state storage itself will need to survive the scene change, I'd recommend that you store the state in an Autoload script. Then, on scene change, retrieve the button states and restore them.

by (22,674 points)

Wouldn't that mean I have to make let's say 5 different variables for each button? I want one button to be disabled seperatly

I don't think so. I'd probably just create a Dictionary that is keyed by the buttons themselves with values representing their state. Then...

  • When a button's state changes, you'd record it in the Dictionary
  • Upon scene change, you'd spin through that Dictionary and restore the states as recorded.

Huh, that actually helped a ton! I also did not know how to use dictionaries, but I researched that. So I learned to things today :3

Thank you so much!

Happy to help. Post back if you get stuck.

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.