Search Unity

Stop colliders from blocking events

Discussion in 'UGUI & TextMesh Pro' started by Sir-Spunky, Mar 3, 2016.

  1. Sir-Spunky

    Sir-Spunky

    Joined:
    Apr 7, 2013
    Posts:
    132
    Is there some way to make events pass through 3D colliders rather than being blocked by them, while still being detected by them as events?

    In other words, I want the event to both register on the first object hit, then pass through the object and also trigger events on the object behind it.

    In my strategy game, I want units to be selected when clicked on, but I still want dragging of the map to work even when the pointer is over a unit. Right now, the unit's sphere collider (used for selection) blocks the event from reaching the terrain collider, so I cannot trigger both events simultaneously.

    I use Event Triggers, so I guess I would either need the Event Trigger to send its own event raycasts to objects behind it, or if I could make the Camera's Physics Raycaster component to use something like Physics.RaycastAll instead, to return all hits and not stop at the first.
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Well PhysicsRaycaster all ready does a RaycastAll so it has a list of all objects. what the EventSystem doesnt do however is continue passing the message through if it finds one that should receive the message. You'd need to write that logic yourself.
     
  3. Sir-Spunky

    Sir-Spunky

    Joined:
    Apr 7, 2013
    Posts:
    132
    Thanks for answering! That's good to know.

    Is there an easy way to find the complete list of hits from the Physics Raycaster? I tried looking at PointerEventData that is sent with the event, and found pointerCurrentRaycast, a RaycastResult, but it only seems to contain a single raycast hit.

    Maybe I need to do something more tricky, like extending Physics Raycaster or the Event System script?
     
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Unfortunately no real nice way. The PointerInputModule (Standalone derives from this) clears its hitResultCache right after it sets the currentRaycast. You might be able to derive from Standalone and reimplement that GetMousePointerEventData function such that it doesnt clear the list after (should clear before it tries to get the list again) and make a property to expose the list externally (current protected)
     
  5. daniel_martins

    daniel_martins

    Joined:
    Jan 3, 2018
    Posts:
    5
    Has this changed in the meantime? Is there a better workaround?
     
    drewjosh likes this.