When reloading the same scene which is currently the current_scene, the script attached to the root node of the scene disappears. Every other script within the scene still appears. I tested this, by putting this:

func ready(): print("[DEBUG] I have a script!") into the script of the root node of the scene. Is this a known issue, or am I doing something wrong?

I’m reloading the scene with: @onready var startMenu:PackedScene = preload("res://ui/start_menu.tscn")

func _on_reload_pressed(): get_tree().change_scene_to_packed(startMenu)

Using the latest stable version

  • simple
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    Are there no errors? Either way you can just use get_tree().change_scene_to_file("res://ui/start_menu.tscn") if your goal is to load a scene from a file, usually packed scenes are for adding to your current scene.

    • Smorty [she/her]@lemmy.blahaj.zoneOP
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      When switching to get_tree().change_scene_to_file() the same thing accurs. The only errors I’m getting are the ones related to other Nodes trying to interact with the script, which isn’t there. Here an example of a button, trying to call a function, as it is connected to it via a signal: E 0:00:05:0925 emit_signalp: Error calling from signal 'pressed' to callable: 'Node::_on_reload_pressed': Method not found. There are no other errors when switching the scene like this.

      For further clarification, here is the scene I’m in:

      The script attached to StartMenu does not work, but the script attached to Control does. Again, this only occurs when changing the main scene. I defined this scene as the main scene in the project settings, and the first time it loads (on startup of the game) it works no problem. Just on that second load, the get_tree().change_scene_to_file() maybe somehow messes it up.

      • simple
        link
        fedilink
        English
        arrow-up
        2
        ·
        1 year ago

        Seems like you might have an issue with how you set up the signals. So does _on_reload_pressed work before switching scenes, then stops working after switching? Are the signals connected to Control or StartMenu?

        Also if you send me the project I can take a quick look.