0 votes

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.

asked May 24 in Engine by PopeRigby (24 points)

1 Answer

+1 vote

you could bound your input for shooting and gameplay to unhandledinput(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

answered May 24 by LoneDespair (315 points)

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"):

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.

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.