Prevent game from unpausing when I press "ui_accept" during pause menu

martynbizmartynbiz Posts: 13Member

I have the following code in my pause menu script to pause the game when the menu is displayed:

get_tree().paused = true

However, as I toggle between screens within the pause menu by using the "ui_accept" input, it unpauses the game in the background even while the menu is still showing. How do I not unpause the game with this input. I don't recall ever telling Godot, unless this is default behaviour. How can I fix/prevent this and unpause the game by my choosing?

Tags :


  • DaveTheCoderDaveTheCoder Posts: 516Member
    edited October 14

    Interesting. I'm working on a game that's strictly mouse/touch input. I don't use keyboard input for anything.
    I just tried pressing the Enter key (one of the input actions mapped to "ui_accept") while the game is paused, and it unpaused it. So it must be default behavior.

    To prevent this, maybe you could add your own code that handles a "ui_accept" action, and does nothing if the game is paused. I'll try that and see if it works, and post the result here.

  • cyberealitycybereality Posts: 2,089Moderator
    edited October 14

    Just set you own input mapping. I've never used the default ones for anything (just don't delete them, cause they are used in the editor).

  • martynbizmartynbiz Posts: 13Member

    I don't want to change ai_accept as even in the pause menu, I use it for selecting settings while the game is running (e.g. change match tactics in a soccer game). So, for example, removing enter key from ui_accept would perhaps solve the issue of preventing unpausing, but would mean that I can't then use the enter key for selecting items in the pause menu.

  • cyberealitycybereality Posts: 2,089Moderator

    I just tested it, and I don't see any issue with pausing and unpausing, even when pressing the enter key. I would suspect there is some bug in your code. Maybe do a global search for "get_tree().paused" (Control + Shift + F) and see if there is some other script that is inadvertently changing the pause state.

  • DaveTheCoderDaveTheCoder Posts: 516Member
    edited October 15

    I found that in my game, the reason that pressing the Enter key was pausing/unpausing the game was that it was causing my onscreen pause-button to be pressed. I solved that by setting the button's focus_mode property to Control.FOCUS_NONE.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file