Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Feature Request Non-alloc and filtered Collision2D.GetContacts().

Discussion in '2D Experimental Preview' started by AlkisFortuneFish, May 5, 2017.

  1. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    I was just wondering, any plans on adding a GetContacts() method to Collision2D, making it match the Collider2D and Rigidbody2D APIs? We just need to get the contacts for a particular collision and the contacts property will obviously allocate memory, plus being able to use CollisionFilter2D would be a nice bonus.

    I have currently worked around this by actually calling GetContacts() on the collider, filtering out the contacts that are not relevant.

    Loving the combination of the filter API and useFullKinematicContacts so far, it allows removal of several kludges we've had to do, such as using triggers for hit boxes on kinematic rigidbodies and then having to do boxcasts to estimate contact points.
     
    MelvMay likes this.
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    There are long term plans for new collision callbacks for both 2D & 3D physics.

    In the short term for 2D physics, there are plans to make the existing "contacts" property (array of ContactPoint2D) only allocate once, when it is called. More importantly yes, a GetContacts call on Collision2D is going to be there too.
     
    AlkisFortuneFish likes this.
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
  4. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    We've got a meeting in two weeks about this subject to design how we're going to provide access to physics "events" rather than the expensive callbacks we have now. This'll be for both 2D & 3D systems. It's super important that we get this done ASAP.
     
  6. der_r

    der_r

    Joined:
    Mar 30, 2014
    Posts:
    259
    Sounds awesome. Super excited about the direction Unity is taking lately.
     
  7. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    Any updates on this? Any work arounds? I am getting huge GC Alloc for a simple 2D Android mobile game.
    Physics2D.ConvertCollision2DForScript is the culprit.
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    You can follow the thread here but the short of it is that a no-gc-alloc for 2d/3d physics callbacks just landed in 2018.3.0b11 and 2019.1.0a7. I also posted that on Twitter here.
     
  9. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    Can't wait to try it out! Downloading 2018.3.0b11 right now. It is such an issue (the stuttering) that I'm considering releasing my game using this beta version if it works alright.

    Edit: Wait a second. The hub only has .0b9? :(
     
    Last edited: Nov 10, 2018