Working button to return to the scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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?

:bust_in_silhouette: Reply From: codabase

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…

func _on_levelskey_pressed() → void:
get_tree().change_scene(“res://levelscreen/levelscreen.tscn”)

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 :wink: and I hope this helped you

codabase | 2023-03-25 18:15

This method did not work. But thank you

saraalipour | 2023-04-14 17:02

:bust_in_silhouette: Reply From: saraalipour

The problem is solved, but if you have this problem, be sure to use this line of code. It worked for me


get_tree().pused=false
get.tree(). change_scene(“”)