#cannot change a scene to packedscene

8 messages · Page 1 of 1 (latest)

near iris
#
//# this is a valid scene path the scene opens perfectly normal and runs too no errors
const MAIN_MENU = preload("res://Scenes/main_menu.tscn")

func _ready() -> void:
    //# prints ""
    print(MAIN_MENU.resource_path)

    pause_menu.quit_button.pressed.connect(func() -> void:
        Cursor.play_select_music()
        await Cursor.ui_animation_player.animation_finished
                //# prints <PackedScene#-9223371923356907660>
        print(MAIN_MENU)
                //# prints true
        print(MAIN_MENU is PackedScene)
        get_tree().call_deferred("change_scene_to_packed", MAIN_MENU)
        )

//# errors on button press
E 0:00:08:080   instantiate: Failed to instantiate scene state of "", node count is 0. Make sure the PackedScene resource is valid.
  <C++ Error>   Condition "nc == 0" is true. Returning: nullptr
  <C++ Source>  scene/resources/packed_scene.cpp:141 @ instantiate()

E 0:00:08:080   change_scene_to_packed: Parameter "new_scene" is null.
  <C++ Source>  scene/main/scene_tree.cpp:1536 @ change_scene_to_packed()
#

cannot change a scene to packedscene

marsh umbra
#

I wonder if, by calling deferred on the tree rather than the object the script is attached to, there's a gap where the stringified function name can't be traced back to a function.

Is there a way to do call_deferred("get_tree.change_scene_to_packed", MAIN_MENU)?

near iris
#

the resource doesnt have valid path for some reason

func _ready() -> void:
    //# prints ""
    print(MAIN_MENU.resource_path)
near iris
#

changing to load from preload made it work

#

not sure why but it do.

waxen scroll
#

Having the same problem here, putting 'load' instead did fix it but every button doesn't work