- Home /
IPointerDownHandler on GameObject behind the UI element with IdragHandler ?
Hello everyone. I have All_over_screen UI element with:
public void OnDrag(PointerEventData eventData) {
//code
}
now i want to interact with 3d objects on the scene with EventSystems:
IPointerDownHandler,
IPointerUpHandler,
IDragHandler,
IEndDragHandler,
IBeginDragHandler
I put PhysicsRaycaster on camera and interaction script on GameObjects i want to interact with:
public class Interactable : MonoBehaviour,
IPointerDownHandler,
IPointerUpHandler,
IBeginDragHandler,
IDragHandler
{
public void OnBeginDrag(PointerEventData eventData) {
Debug.Log($"OnBeginDrag on {name}");
}
//...the rest of debug implementations
}
I also put CanvasGroup on All_over_screen UI to be able canvasGroup.blocksRaycasts = false; and trying to:
public void OnPointerDown(PointerEventData eventData)
{
_canvasGroup.blocksRaycasts = false;
}
But the issue is I don't catch on the Game Object on scene:
public void OnPointerDown(PointerEventData eventData)
{
Debug.Log($"OnPointerDown on {name}");
}
sho the question is - how to pass through the UI element to the game object to catch OnPointerDown event on the object and if not cathed, proseed with OnDrag on the UI?
Answer by misher · Nov 19, 2019 at 05:04 PM
You can't reach the object behind the UI in 3D scene. Please note, even if there is a transparent ui element which is marked as raycast target, it will receive event and won't let you interact with objects in the scene. For example, if you have a background image on your canvas, even if it's 100% transparent, toggle off raycast target in Image component.
Your answer
Follow this Question
Related Questions
Why Does IsPointerOverGameObject Not Work with GUILayout Controls? 0 Answers
Event System Problems 1 Answer
Canvas appearing over my cursor doesn'tr trigger OnPointerExit ! 0 Answers
Force EventSystem to updating when application not in focus 1 Answer
Best way to disable all UI events except for one button 0 Answers