0 votes

Hello, I have been creating a "Scene Switcher" recently, which works for the most part. Everything in the code works, however in the new instanced scene I can't click on any options in the pause menu, but I can open and close the menu with the key I've mapped to it. I also have a checkbox in the new scene which I can't click as well. I'm very close to having this work, but the scene is essentially frozen. Not sure what to fix, any help would be greatly appreciated. Here's the code:

change_scene (autoloaded scene):

func change_scene(node, delay = 0.5):
    var pause_menu = preload("res://Scenes//PauseMenu.tscn").instance()

    var n = ResourceLoader.load(node)

    get_tree().create_timer(delay)
    animation_player.play("fade")
    yield(animation_player, "animation_finished")

    get_tree().get_root().get_node("Main").queue_free()

    var new_scene = n.instance()
    get_tree().get_root().add_child(new_scene)
    #get_tree().set_current_scene(new_scene)

    animation_player.play_backwards("fade")
    yield(animation_player, "animation_finished")

    get_tree().get_root().add_child(pause_menu)

    emit_signal("scene_changed")

The PauseMenu (separate scene):

func _ready():
    $VBoxContainer/Map.grab_focus()

func _physics_process(delta):
    if $VBoxContainer/Map.is_hovered() == true:
        $VBoxContainer/Map.grab_focus()
    if $VBoxContainer/Options.is_hovered() == true:
        $VBoxContainer/Options.grab_focus()
    if $VBoxContainer/Quit.is_hovered() == true:
        $VBoxContainer/Quit.grab_focus()

func _input(event):
    if event.is_action_pressed("PauseMenu"):
        $VBoxContainer/Map.grab_focus()
        get_tree().paused = not get_tree().paused
        visible = not visible



func _on_Resume_pressed():
    get_tree().paused = not get_tree().paused
    visible = not visible


func _on_Quit_pressed():
    get_tree().quit()
in Engine by (16 points)

1 Answer

0 votes

You're adding the pause_menu after the new_scene.¹ Assuming the PauseMenu is a Control-node as well, it'll consume all input events, thus your buttons don't react.

On an unrelated note: Paths tolerate double slashes, but don't require them (other than in the beginning). So "res://Scenes/PauseMenu.tscn" is the same as:

"res://Scenes//PauseMenu.tscn"
"res://Scenes///PauseMenu.tscn"
"res://Scenes////PauseMenu.tscn"
"res://Scenes/////PauseMenu.tscn"
# and so on...

Also what you're passing to change_scene isn't a node but a path.

¹ However, I'm not sure why... Seems to have nothing to do with changing scenes?

by (10,315 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.