Game doesn't run when two scenes link each other.
Asked Answered
U

5

0

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.

Undoing answered 28/6, 2023 at 19:26 Comment(0)
G
0

Does a error occure? What does the debug console say?

Ginsberg answered 28/6, 2023 at 19:29 Comment(0)
U
0

Ginsberg

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 ---

Undoing answered 30/6, 2023 at 20:26 Comment(0)
S
0

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))

Sedimentation answered 1/7, 2023 at 11:0 Comment(0)
U
0

Sedimentation
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.

Undoing answered 9/7, 2023 at 18:17 Comment(0)
S
0

Undoing ¡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.

Sedimentation answered 15/7, 2023 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.