Menu scene not executing script after loading

Godot Version



Hi, I am having an issue with my main menu scene. I have a main menu set up with two buttons, one that loads the main level and one that exits the game. Within my game level, I have a button that exits back to the main menu. I am using the function change_scene_to_packed() to do this. Upon starting the game, the main menu works as normal. The play button loads the level and the exit button closes the game. Upon loading into the main level, everything also seems to work as normal.

The problem is, upon returning to the main menu using the exit button in the level, the main menu scene seems to not function. The scene visually appears to load as the text, background, and buttons all appear. The buttons animate properly when pressed, but nothing happens. In the main menu script’s _ready function, I put a test print statement. The statement prints when starting the game initially, but not when loading to the menu from the level. Its as if the main menu is not executing its script when being loaded from the level, but I’m not sure why.

I saw someone with a similar problem who was pausing their game without unpausing it, which was causing the issue. As far as I understand, this is referring to the Scene Tree’s ‘paused’ property, but I don’t have any code that changes this property.

This is the code in the level script that changes the scene back to the main menu

It seems as a new forum user I am only able to upload one image, so I figured the code in the level script that loads the menu would be the most relevant. I also have the snips of the main menu script and the script for the UI within the level, so please let me know if any of you want to see those or anything else in the project.

I am a beginner, so any suggestions are appreciated.

Can you send a screenshot of your menu script here maybe the issue is there.

Here it is

I don’t see anything wrong with both scripts. Sorry I can’t help, maybe someone else might have faced this issue before.

Hello !
What scene are you running as the Main Scene (in the Project Settings) ? Do you use another scene ?
It could be that there is a ColorRect node or another Control node is blocking your input. These nodes have a mouse filter property, that blocks all input if set to stop (its default value).
If that were the case, if would explain why the buttons are still animated although not responding. But it doesn’t explain why the _ready function doesn’t start.

Also try this : [4.0 RC 1] Can't switch to packed scene that was started in using change_scene_to_packed · Issue #72921 · godotengine/godot · GitHub
→ using the change_scene_to_file instead of the change_scene_to_packed function

1 Like

Hi, thanks so much! Using change_scene_to_file instead of packed for both the menu and level scripts seemed to fix the issue. Upon further inspection with the remote tab, it seemed the root of the issue was that the main menu script was not attaching to its node upon being loaded by the game level script.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.