1
\$\begingroup\$

I'm working on a small platformer game to learn Godot, and I have a main scene which is just a menu with a "start" button. The levels go from 0 to 3, and a "level complete" screen pops up between them.

Everything works as expected until I try to return to the main menu, where the game immediately closes. There is no error message, so I set breakpoints and watched the scene tree, where MainMenu successfully gets loaded under root. The _ready method runs normally, but then _on_tree_exiting gets triggered without hitting the breakpoint I set in _process. I'm using get_tree().change_scene_to_file("res://ui/main_menu.tscn") to switch my scenes, and I've tried using the deferred version of it as well. Is there something I am doing to cause the scene to be immediately unloaded, or is there something else happening that I should be aware of?

MainMenu is marked as my main scene and is the entrypoint to the game if that is important.

My first guess was that it was unhappy I loaded a scene which was previously unloaded when I left the menu the first time, but I'm visiting my "level complete" scene 3+ times with no issues so it seems Godot is fine reloading scenes as needed.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Can you walk us through the steps to create a Minimal Complete Verifiable Example of this problem, starting from a new, empty Godot project? \$\endgroup\$
    – DMGregory
    Commented Jul 27 at 17:42
  • \$\begingroup\$ @DMGregory While working to recreate it as a minimal example, I figured it out. It was a PEBKAC, but I'll put it in an answer since the behaviour was a bit counter-intuitive to me and maybe it'll help someone else. \$\endgroup\$ Commented Jul 27 at 20:28

1 Answer 1

4
\$\begingroup\$

I was trying to recreate my game as a new project, and the problem apparently came from copy-pasting UI components. I copied all my other UI buttons since I wanted them to be the same size/style/etc, but it kept all the previous signals attached as well. I guess I didn't understand how close the engine kept the code and scenes so I just assumed that any bindings I had wouldn't be preserved when making copies from the 2D editor. I can't think of a scenario where I want two buttons in the same scene doing the same thing so the behaviour still seems a bit weird to me but at least I learned.

In short, my menu button was triggering 3 different _on_pressed callbacks at the same time, so after deleting the extra signals it's ok now.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Good find! Thank you for sharing the info to help others. \$\endgroup\$
    – DMGregory
    Commented Jul 27 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .