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.
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.
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.
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.
You can follow the thread [here ]( Physics.Contacts GC activity page-2#post-3807838)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.
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.