How do I make a pause menu take mouse input?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PopeRigby

How do I reroute a certain key bind to a different function under a specific circumstance? I’m trying to make a pause menu that pops up when you hit Esc while in the game, and I want the menu to be able to take left click input, but left click is already bound to a shoot function, so I can’t click on the menu. At least I think that’s why it’s happening.

:bust_in_silhouette: Reply From: LoneDespair

you could bound your input for shooting and gameplay to _unhandled_input(event):
which would block inputs that happens on gui’s that filters mouse

but that option adds a LOT of latency, which could be an issue for your game

-as a work around you could have a canvas layer with its layer lower than all of your gui

-add a child control node

-connect its signal for mouse enter and exit for enabling and disabling your mouse inputs for your gameplay

-make sure to set it to full rect on layout

-whenever the mouse enters your control node it means that its not being blocked by a gui, else there is a gui on top

its a clunky solution but it gets the job done, you could even use singletons for this

I’m having a new issue while trying to implement the _unhandled_input method you were describing. popup() isn’t getting called when putting it in a _input function:

func _input(event):
    if event.is_action_pressed("menu"):
        print("pre-popup")
        popup()
        print("post-popup")

These print statements are working, it’s just popup() isn’t. The weird thing is, popup() works when it’s in _process function, so I don’t know what that’s about.

PopeRigby | 2020-05-24 19:52

it works for me, maybe test it on its own scene? to make sure nothing else is interfering
or try other inputs to debug if which is the problem eg “ui_up”

as for the unhandled_input
it will not detect inputs that are being registered/detected by a gui
most gui registers mouse inputs by default

LoneDespair | 2020-05-25 16:42

Managed to fix it. Thanks for your help anyway though!

https://godotforums.org/discussion/22961/popup-isnt-working-when-being-called-from-within-input#latest

PopeRigby | 2020-05-25 17:10