I have two scenes that have a button that when clicked runs the following code:

extends Button

#@export var transto: Resource
@export var transto: PackedScene

func _on_pressed():
get_tree().change_scene_to_file(transto.resource_path)
#get_tree().change_scene_to_packed(transto)

For each scene I dragged the other scene into the transto variable. The game works just fine if one scene had transto assigned and fails to load when both are.

For reference as to what I am trying to do, I am making a menu that can go from one menu to another and then back to the first menu.

klaas

It does nothing. The window will pop up like it is about to run, then just shut down.

This is all the output window says

--- Debugging process started ---
Godot Engine v4.0.2.stable.official.7a0977ce2 - https://godotengine.org
Vulkan API 1.2.133 - Forward+ - Using Vulkan Device #0: AMD - AMD Radeon(TM) R4 Graphics

--- Debugging process stopped ---

in my responsive UI demo, the buttons don't switch scenes.
every page's root Control has this script:

extends Control


func _on_show_button_pressed() -> void:
	set_visible(true)


func _on_hide_button_pressed() -> void:
	set_visible(false)

and the Buttons' pressed signals are connected to these functions so that, for example when pressing a Back button

  • the current page becomes invisible
  • the main menu becomes visible

you don't have to activate and deactivate the Controls separately, because they automatically become active when visible and inactive when invisible (unlike Node2D and Node3D).

this looks the same as switching scenes, but it's not (plus the transitions can be animated by animating before set_visible(false) and after set_visible(true))

    8 days later

    Sosasees
    Don't quite understand what you are doing there but thanks anyways. Ended up just putting the entire menu in one scene and moving the camera around. Its a but cluttered but seems to be working for now.

      6 days later

      MegaSeraphimon ¡i wish you good luck! 🙂

      this solution can break easily when the viewport changes aspect ratio. and it's possible to use off-screen controls with the keyboard since they don't get disabled (hidden), which confuses or frustrates users when they press Space and something unexpected happens.

      i highly recommend learning about signals so you can properly show and hide panels like me.