#Scene not functioning after getting loaded via get_tree().change_scene_to_packed()

24 messages · Page 1 of 1 (latest)

sharp canyon
#

So I have a pause menu in my game and I addded a button that returns to the main menu scene, but when I press the button, the main menu gets loaded but doesn't seem to work. I'm not sure if it's not loading its script or what, but the buttons don't work and the _ready() function isn't getting called at all.

I made sure the pause was off, and that the main menu screen process is set to "Always". Still not working. Not sure what I'm not seeing here.

Pause Menu loads the main menu with the following function:

    print("main menu button pressed")
    get_tree().paused = false
    print("pause state: " + str(get_tree().paused))
    get_tree().change_scene_to_packed(main_menu_scene)```

and the scene is packed as follows:

`var main_menu_scene = preload("res://Assets/UI/start_screen.tscn")`
hushed cedar
#

Do you get any of the print statements in that function?

#

Also, print out the value of he scene var or tu a breakpoint in that function and step through it

sharp canyon
#

I get both print statements there, but not the one in the _ready function of the main menu (even though I can see the main menu and it is loaded onto the remote scene.

short nebula
#

@sharp canyon In the Godot docs it says that after removing a node from the scene tree and adding it a second time _ready() will not be called, and also that you can bypass this using request_ready(). Could this be the issue?

#

this can be found in the documentation for the "Node" class, btw

sharp canyon
#

ahhh ok, so that explains why _ready isn't being called again, thanks. The buttons should still work though right?

#

I connected the buttons using the BaseButton pressed() signal

hushed cedar
#

Set a breakpoint in the function that is called by the signal and see if it stops there or not. That will also tell you the values of scenes, etc in the debuggers, very useful info

sharp canyon
sharp canyon
#

I did find that this error is getting outputed when I press the buttons and they do nothing:

E 0:00:08:0052 emit_signalp: Error calling from signal 'pressed' to callable: 'Control::_on_start_button_pressed': Method not found. <C++ Source> core/object/object.cpp:1082 @ emit_signalp()

#

The buttons work when I first launch the start scene, but upon reloading it using get_tree().change_scene_to_packed(main_menu_scene)

something seems to break, maybe with the signals?

#

It's worth noting that the button signals are connected via inspector, not code.

hushed cedar
#

🤔 that error sounds like it's saying the pressed signal can't connect to _on_start_button_pressed

#

Try disconnecting and connecting the signals again to see what happens maybe?
Does the scene you are loading via code also have that script with those signals connected?

sharp canyon
#

Reconnecting the signals didn't help. How can I check if it still has the script attached? It should I think, since the main menus scene is saved with the buttons, signals and script attached, but not sure how to make sure.

#

The error message makes it sound like the scene is being loaded without its script or something but I don't know why that would be the case.

hushed cedar
#

Here is where breakpoints will be invaluable. You can add them to sthe script and then when you run the game it will actually stop where you put the breakpoint. In the Editor, you can see all the properties of your scenes and objects in the hierarchy.

humble ginkgo
#

i think im having the exact same issue as you are here i get the same error and ive also noticed by using the remote tree that when going back to the scene the script doesnt keep its link to the scene or whatever. Breakpoints dont do anything because the script isnt even loaded.

sharp canyon
#

Didn't know the script showed up on the bottom there. You're right Djaruun, that's exactly what's happening.

#

Not sure why though. Maybe a bug?

#

I think I got it working! I was using:

var main_menu_scene = preload("res://Assets/Scenes/start_screen.tscn")

To load my scenes, but changing it to load instead of preload seems to be working perfectly now.

Not sure if this is a bug, or something inherently different between the two methods that I' m not aware of.

humble ginkgo
#

idk tbh i dont even think i changed anything about it in particular and now it has benn working since