- Home /
Alternative for non-existing EventSystem.IPointerOverHandler
Hi,
I use the various EventSystems.EventSystem.IPointer[...]Handler interfaces to retrieve pointer interactions with a collider on a certain layer.
Problem is that I can track when pointer enters and leaves the collider, but I can't seem to determine wether the pointer is already over the collider's position before the collider is created.
IsPointerOverGameObject does not seem to work in the same way as the IPointer... interfaces. For example, OnPointerClick is not called when the collider is blocked by a UI element. But IsPointerOverGameObject always returns true so I see no use for it.
Q: Is there a way to determine to check each frame wether the Pointer is over a game object in a certain layer and not blocked by UI in the same manner as the other pointer event handlers?
Cheers, Rob
If no Physics Raycaster is added to any game object then IsPointerOverGameObject does return false when over a non UI object.
But the IPointerEventHandlers require a Physics RayCaster component added to the main camera.
The IPointerEventHandlers seem be to the proper way to handler the pointer events, but are thus not able to function simultaneously with IsPointerOverGameObject...
Answer by RobGraat · Mar 19, 2016 at 07:36 PM
Ok, got it working purely using IPointerEventHandlers by simple setting the game object to inactive and setting it to active in a later frame.
The OnPointerEnter method is then called when game object becomes active. From there on I can track wether the Pointer is over the plane collider using OnPointerExit/Enter.
Feels like an hack though.
(I use this to disable the tile selection indicator over a hex grid when the cursor is over UI elements. And the indicator should not be active when the cursor happens to be over the UI after the level is loaded.)