- Home /
New Input System: Detect if input is used by UI
I'm trying out the new input system - and I'm impressed by the flexibility it offers!
I'm doing a game with mouse input. I want to do a combination of onscreen UI buttons and direct mouse manipulation (clicking and dragging on non-UI objects).
To do this, I use the InputSystemUIInputModule with the default UI action-map to drive the UI. On top of that, I've added my own "world objects" action-map for the non-UI objects. This one picks up mousemovement and clicks as well.
This works just fine, except that I get the actions of my world objects action-map triggered, when using the buttons of the UI. I understand, why this happens, as I have both maps running. But I really need it to not happen!
So just to be clear - what I want:
If a UI Button is clicked, I don't want my world objects action-map to be triggered as well.
Any help or clues on how to achieve this would be most valued! Thanks so much in advance! :-)
Answer by Saseska · Sep 07, 2020 at 10:16 AM
Recently I was looking into this problem as well and found only this approach. To determine that the click was used by UI you can check EventSystem.current.IsPointerOverGameObject(), if it's true that means that UI has detected clicks/pointer move or whatever. And you should also set up your GraphicRaycaters to block only what your canvas uses.
p.s. if there are better solutions - i'd like to know them too :)
Answer by PB_B · May 07, 2021 at 09:28 AM
Bump, I'm also looking for a solution here. The reason EventSystem.current.IsPointerOverGameObject() isn't working for me is I don't want all UI elements to be ignored, only some.
If the elements have the "Raycast Target" Property set to false, EventSystem.current.IsPointerOverGameObject() will return false for them. Turning off "Raycast Target" is, iirc, recommended performance-wise anyway for non-interactable elements.
The function is misnamed imho and should be called IsPointerOverRayCastTarget() by the unity team instead.
Your answer
Follow this Question
Related Questions
Use iOS "ESC" back swipe from left edge 0 Answers
How do I detect when UI events are triggered on *any object*? 1 Answer
OpenXR Continuous Turn and Movement not working 0 Answers
Gamepad menu navigation with uGUI not working as expected. 1 Answer
each character doubled in inputfield in build but not editor on ubuntu 16.04 2 Answers