#When Returning to the Main Menu from the Pause Menu, all buttons do not function

32 messages · Page 1 of 1 (latest)

jaunty wharf
#

Hello, I am experiencing an issue with Godot 4.0.2, where functionality is broken upon transition back to my main menu scene.

Reproduction

  • Open main menu, select "Level start"
  • Level 1 scene opens
  • in level 1 scene, pause menu is available
  • Open the pause menu, and select the button to go to the main menu
    MainMenu.Pressed += () => GetTree().ChangeSceneToFile(MainMenuPath);
  • After returning to the main menu, none of the buttons are functioning as expected (none of the code appears to run for the corresponding pressed signals

Any help is appreciated, I've had this issue for awhile in general when trying to reload scenes, or transition to already loaded scenes, but I really want to resolve this issue, because it is becoming quite a big issue for me, that keeps putting roadblocks in front of me!

Let me know if you need any further context, I will provide some snippets below!

Code Snippets

MainMenu.cs

using AutoAvians.autoloads.transition_manager;
using Godot;
using GodotUtilities;

namespace AutoAvians.ui.menus.main_menu;

public partial class MainMenu : Menu
{
    [ExportCategory("MainMenu Buttons")]
    [Export] private Button _levelSelectButton;
    [Export] private Button _optionsButton;
    [Export] private Button _quitButton;
    [Export] private Button _startButton;
    
    [ExportCategory("Main Menu Scenes")]
    [Export] public PackedScene FirstLevel;


    public override void _EnterTree()
    {
        base._EnterTree();

    }

    /// <summary>
    ///     Called when the main-menu is instanced, sets up signals and vars
    /// </summary>
    public override void _Ready()
    {
        base._Ready();
        _levelSelectButton.Pressed += OnLevelSelectPressed;
        _startButton.Pressed += OnStartButtonPressed;
        _quitButton.Pressed += OnQuitButtonPressed;
        _optionsButton.Pressed += OnOptionsButtonPressed;
    }

// Other button methods ommitted for conciseness
    /// <summary>
    ///     Called when the start button is pressed on the main menu
    /// </summary>
    private void OnStartButtonPressed()
    {
        GD.Print("Start Button Pressed");
        TransitionManager.TransitionInstance.LevelStart(FirstLevel);
    }
}

TransitionManager.TransitionInstace.LevelStart()

    public void LevelStart(PackedScene newScene)
    {
        string levelFile = newScene.ResourcePath.GetFile();
        string levelName = Path.GetFileNameWithoutExtension(levelFile);
        Signals.Instance.EmitSignal("LevelStarted", newScene, levelName);
        GetTree().ChangeSceneToPacked(newScene);
    }

Return to main menu call from **PauseMenu.cs ** _Ready()

 MainMenu.Pressed += () => GetTree().ChangeSceneToFile(MainMenuPath);
#

I think I have mostly resolved the issue with these buttons, I now just have an issue revolving around some of the things I expect to work when re-starting the level, not working as expected

#

Turns out, I was calling GetTree().Paused = true; elsewhere, and so when I transitioned back to the mainmenu, nothing was working because the scene tree was paused lol

dull storm
#

THANK YOU SO MUCH

#

I had the same problem like 2 months ago

#

hadnt solved it until now

jaunty wharf
#

No problem, happy this helped!

#

One other thing to note, I have some other instances where I'm having issues with things not reloading properly, and I needed to move a lot of things to csharp _EnterTree() instead of _Ready since ready didn't seem to get called everytime

dull storm
#

hm thats weird

jaunty wharf
#

I also learned there is a bug where signals do not automatically disconnect from custom signals in C# Godot, so you need to use _ExitTree() to disconnect them

#

Which seems to be throwing other errors for me

dull storm
#

thanks

jaunty wharf
#

No problem, happy to help!

dull storm
#

do you notice any performance gains using c#?

#

ive been thinking about swapping for a while but dont see any reason to

jaunty wharf
#

I mostly use it because I want to learn C#, moreso than for optimization

#

I think you have to be at a pretty high level to use C# for performance in Godot 4 at least

dull storm
#

are you still able to export to mac and android and stuff

jaunty wharf
#

All exports work except web right now, as far as I can tell

dull storm
#

okie dokie

#

thanks again

jaunty wharf
#

No problem!

jolly leaf
# jaunty wharf One other thing to note, I have some other instances where I'm having issues wit...

LOL. It's the middle of the night here and I'm just reading your messages. I'll have to try this out in the morning because that might very well be my issue as well. 😂 Basically my issue is the exact same except it doesn't happen in the main menu (I most likely have process mode set to always in that one) but when I access the settings menu from the main menu (so basically: it works when I start the game, go to the settings menu from the main menu and press the back button but not when I go into the game, use the pause menu to go back to the main menu and THEN go to the settings menu).

Ahhh, this might be it. 😂 Can't wait to try it in a few hours (I should really get some sleep LOL).

Thank you so much.

jaunty wharf
#

No problem! Feel free to DM me if that doesn't work

#

I'm happy to lend a hand

jolly leaf
# jaunty wharf I also learned there is a bug where signals do not automatically disconnect from...

What I did was build a bunch of 'converter' glasses that basically convert built in signals to IObservables so, for instance, when I want to check for a pressed signal I can do something like _menuButton.WhenPressed() and then subscribe to that instead of going through connecting to the signal, adding some sort of OnPressed() method and doing stuff there.

I see the issue is with the custom signals and not the built in ones. Basically I've been using ReactiveX for my custom 'signals' as well which has been working great so far for me.

jolly leaf
jaunty wharf
jolly leaf
#

Yep!

#

Yeah sure! I'll help out!

jaunty wharf
#

Let me know how the reloading stuff goes! Hope this fixes your issue!