Godot Version
Godot 4.6.2
Question
I am currently trying to make my scenes switchable between scenes. I watched a tutorial and it worked between my first scenes and second one. But when I try for the third it won’t click. At first it was because I was accidentally using the same code window. So I made a new script but it still won’t switch. How do I fix this? Or can I do a “click anywhere to continue” type of thing?
There could be many reasons, but it’s difficult to say what causes the problem in your specific case because there’s no code and scene tree for us to look at.
If you want something to happen on a button click, you should connect and listen to the button’s pressed signal. Here’s an example script that does this:
class_name SwitchSceneButton extends Button
@export_file("*.tscn") var scene_to_switch_to : String = ""
func _ready()->void:
pressed.connect(_on_pressed.bind())
func _on_pressed()->void:
if scene_to_switch_to == "":
print("You haven't set the scene to switch to. Set it via the editor.")
else:
change_scene_to_file(scene_to_switch_to)
Note that you have to set the scene via the editor. Also, this is just an example on how to connect to signals. For a very simple game, this code might be all you need. It doesn’t keep very well for anything more complex.
1 Like