#Any good strategies to prevent click behind overlay ui buttons?

20 messages · Page 1 of 1 (latest)

unreal delta
#

I have some overlay buttons inside a node bundle on top of my core game loop. I allow interaction with the world map by getting the global x/y of the click. If players click an overlay ui button it interacts with the button and ALSO the global click in the game.

Any clean solutions to prevent this from happening? (without a bunch of if conditions to see if the click was first a ui click) * but maybe this is also the cleanest solution?

Another idea I had would be to get a local x/y on screen or a rect of where the ui buttons are and prevent world map interactions when clicks are detected in that area, but that seems hacky and troublesome if the ui is dynamic. Perhaps it's easy to get the rect of a node bundle so this is less troublesome? I ideally don't want to portion off the game map into a smaller rectangle, I like the look and feel of the ui buttons going overtop to allow more real estate in the game.

Open to any ideas. Thanks!

cloud forge
#

My solution is to preprocess in PreUpdate mouse input(save world coords of the mouse, grid coords(for game is grid-based) etc) and save it to my own resource. At that step I also iterate over all Interaction components to check if mouse is over UI and store it as boolean flag. That way I have only one condition to check for when applying clicks in world systems.

unreal delta
#

thanks @cloud forge intersting approach!

hard bluff
#

This might be what you're looking for https://docs.rs/bevy/latest/bevy/input/struct.Input.html#multiple-systems

In case multiple systems are checking for Input::just_pressed or Input::just_released but only one should react, for example in the case of triggering State change, you should consider clearing the input state, either by:

Using Input::clear_just_pressed or Input::clear_just_released instead.
Calling Input::clear or Input::reset immediately after the state change.

unreal delta
#

@hard bluff clearing the the input is way way cleaner! thank you so much for follow up here. this looks like what i need.

#

Input::clear_just_pressed

unreal delta
#

hmmm @hard bluff i don't think this will actually work for me because these things are within the same state

unreal delta
#

nvm i tried using "before" and "after" it didn't work. But using "chain" did the trick.

unreal delta
#

@hard bluff any ideas on how to do this with touch input?

#

looks like a private fn

#

wait.. nvm

#

actually this is for "raw table" maybe something different?

hard bluff
#

Haven't tried before but looks like that functionality might be missing/not public

Might be able to do something like call Input<Mouse button>.press() whenever touches happen to emulate mouse presses

unreal delta
#

making an artifical mouse press for a touch?

hard bluff
#

Yeah that was my thought anyway, then you can absorb the mouse press like normal

#

Might be tricky getting the system order to play nice

#

Also if you need swiping or anything that doesn't fit the concept of a mouse press it wouldn't really work.

unreal delta
#

im thinking touch input just needs a clear function like the mouse press does..

hard bluff
#

Yeah it'd still be good to have that exposed for sure. I just meant as a workaround for now