Search Unity

Question Why Don't I Need a Box Collider for an Event Trigger

Discussion in 'UGUI & TextMesh Pro' started by DockAnkh, Mar 31, 2023.

  1. DockAnkh

    DockAnkh

    Joined:
    Nov 25, 2021
    Posts:
    10
    I thought that for an event trigger to work a gameobject needed a box collider. Otherwise how would the event trigger know what area it was looking at. However, I was having a conflict with some boxed being on top of others and while testing I disabled the box collider on some gameobjects. Oddly, the event system still worked. Is this because the gameobject in question used a recttransform instead of a standard transform? I read some old forum questions where people were saying that a recttransform wasn't enough you needed a box collider. Did this change at some point?
     
  2. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    602
    * Canvas elements like Buttons, "Image", toggles, and other uGUI elements (which always have rect transform) don't need a box collider. Canvas use a completely different non physics based GraphicRaycaster for those events.

    * World objects that are not part of canvas (which typically have regular transform) like Sprite, 3d meshes, rigid bodies and many others need a collider. They require a PhysicsRaycaster for those events to work.

    * As for objects with rectTransform that are not part of canvas, or non gui ojbects placed in canvas that will likely be a mess (maybe with some exceptions) because canvas and world object use completely different coordinates. TextMeshPro-Text (the one meant for world space instead of canvas) might be one of those exceptions since it's supposed to be used in world space, but has rectTransform, in that case it will likely need a collider.


    So while the presence of rectTransform is a strong indicator for which category the object fits, it is not the actual cause and there are plenty of exceptions.
     
    DockAnkh likes this.
  3. DockAnkh

    DockAnkh

    Joined:
    Nov 25, 2021
    Posts:
    10
    Thanks, this is a really great explanation.