Detecting Multiple Coincident Collisions

Hi guys, hopefully this is a simple enough question to answer.

I’m very new to unity, and am using it in some research I’m conducting. My research involves essentially using unity as a real-time physics simulation. I am sending physics data from an animation in Unity over UDP to Matlab wherein it is used to drive some other processes. I am using OnCollisionStay to detect and send contact and physics data, and this data is then sent in packets over UDP (one packet per contact point per collision).

My problem is this: I cannot think how to find how many times OnCollisionStay is called per frame for a given gameobject (i.e. how many objects a given object is colliding with coincidentally). This is problematic, as it means I don’t know how many packets of data will be sent over UDP, and thus don’t know how Matlab should parse the incoming bitstream. Any help?

OnCollisionStay is called once per frame.

An option that would be simplest (my opinion) to know exactly what you’re colliding with:

OnCollisionEnter and OnCollisionExit.

On Enter, add the collision to a List… on Exit, remove it from the list.

Then, in another function of your choosing, you could loop through that list.