- Home /
Access all current Collisions
Hello Unity community
I'd like to access all current Collisions in a scene without having a script on the objects that collide. I currently working on a entity systems based game so I want to avoid using functions in code in scripts placed directly on a object.
So far I understand the collision system of Unity3d OnCollisionEnter() and so on, doesn't contain info of the object the script is on. But I'd like the whole Collisiondata or stuff.
Somebody got an idea?
I'd also like to be able to iterate all collisions in one place rather than having to use the $$anonymous$$onoBehaviour::OnCollisionxxx functions.
$$anonymous$$ost physics engines implement a collision detection & resolution process which goes in discrete phases (i.e. detect all collisions, then resolve all collisions) and I've found it invaluable in the past to be able to iterate all collisions after detection but before resolution.
This allows collision related logic to be centralised rather than handled in 'callbacks' (i.e. $$anonymous$$onoBehaviour::OnCollisionxxx) and allows deter$$anonymous$$istically ordered update - which (for example) allows game logic involving collisions of specific object types to be dealt with before other object types etc.
It seems that the $$anonymous$$onoBehaviour::OnCollisionxxx functions get called in whatever order the collisions happen which is clearly dependent on the ordering of objects in the physics world's representation and thus out of the control of the programmer - also the 'callback' style functions get called once for each object in the collision which makes it inefficient to cache the collision information from the callbacks as it you have to deal with it getting cached twice...
$$anonymous$$
Your answer
Follow this Question
Related Questions
Clarification on updates, physics events order and frequency? 1 Answer
How to make an infinite mass solid body 1 Answer
Can't set Bounce Threshold below .3 0 Answers
More realistic physics? 0 Answers
Entity-Component-System 2 Answers