Topic was automatically imported from the old Question2Answer platform.
Asked By
saraalipour
Hello everyone, I was writing game codes when I encountered a problem. When I put the button to return to another scene in the pause menu, for example, to return to the main scene, the buttons that worked before do not work anymore and the stage does not enter. So I wanted to know if there is a reason that these buttons only work once? Is the problem of returning to the scene again?
I would suggest putting scene change logic inside of Singletons. They’ll stay persistent through your code and allow you more easily control which scenes are being displayed at any given time.
If you are already using these I could provide better advice too!
Thank you for answering my question. Actually, I was not very active in Godot. For example, the scene change code is this…
What is the problem with this?At first, all components work, but they are disabled when returning to the same scene!
saraalipour | 2023-03-25 17:00
What I would do is take that Singleton logic called SceneHandler.tscn or something of that order.
Then have a function called change_scene(scene_path)
From there when you do your on levels key pressed():
SceneHandler.change_scene(res://…)
What may be happening is when you call a change scene from within the same scene, it can kill your current one and you are left with a gap of logic. Basically you want an always running Singleton in the background that controls it all and will never stop running through your games lifecycle.
I hope this was helpful and the article I sent was helpful in the previous post. Please do tell me if it wasn’t or if it needs more details and I’m happy to update it. I’m trying to build some good resources for people working with Godot!
Hopefully more tutorials to come and I hope this helped you