This seems to be unsafe, and I probably should have paid more attention to the Collision Events documentation page, which says "References to these objects should not be kept outside of the event handler."
My question boils down to the best way to keep track of current collision pairs and the contacts in them. My current thought is to create a class that effectively mirrors the data I need from CollidablePairHandler:
Code: Select all
class MyCollisionPair
{
class Contact
{
Vector3 Normal;
Vector3 Position;
}
Collection<Contact> ContactCollection;
Actor OtherActor;
}
Does this make sense? Is there a simpler approach, or is there some similar collection on Entity or Collidable that I can access both outside the context of Space.Update() and inside collision event handlers?
Also, in this case, there's a couple issues I could see cropping up:
1) If ContactCreated is called before InitialCollisionDetected when the first contact is created on a pair, I won't have a corresponding MyCollisionPair yet. I could always ignore ContactCreated for a nonexistent pair, and then add all the contacts in the pair's ContactCollection on InitialCollisionDetected. Does this seem reasonable?
2) If an existing contact has a new position/normal, is a new contact created, or is the old one updated? If the old one is updated, then how do I update my client-side version?