Search Unity

Feedback [Bug/Feature Request] Multiple 2D colliders on the same Z axis trigger incorrectly

Discussion in 'Physics' started by RidgeWare, Mar 20, 2019.

  1. RidgeWare

    RidgeWare

    Joined:
    Apr 12, 2018
    Posts:
    67
    Currently, OnMouse events work perfectly in 2D as long as colliders never overlap, but in isometric games it's very common for sorted/layered sprites to overlap while on the same Z axis.

    It's at this point the OnMouse events become unusable - since the collider which the mouse click triggers is often visually behind another object - and incorrectly fires the OnMouseEnter/Down/etc.

    There is a workaround of sorts; Ditch OnMouse completely & fire a RayCastAll and then sort the colliders it hits by the Y position of the transform. The lowest Y position gameobject then does whatever code you tell it to do. Which seems to work - but is far from ideal and can get rather messy in code, since you miss out on the instant benefits of OnMouse or OnPointerDown. Plus it adds a whole bunch of needless processing.

    So I believe there's a reasonable request here for some kind of new built-in '2DMultipleColliderMouseOver' event method - or possibly even a change to how the renderer/collider shares information between eachother in 2D, so a collider always knows it's 'on top visually', if not physically.
     
    Last edited: May 1, 2019
    suzums and kcfos like this.
  2. RidgeWare

    RidgeWare

    Joined:
    Apr 12, 2018
    Posts:
    67
    Can someone at least acknowledge this is a problem? I don't expect a solution straight away, but it would be nice to at least get a small response from a member of the Unity team.

    Having a sorting layer system which is fundamentally broken for detecting pointers over those sorted objects is a pretty big issue for making 2D games.

    I was told by a moderator this was the correct folder to raise it in.