This project has moved. For the latest updates, please go here.


Setting Body.Enabled=false in OnCollision not supported


I could be doing something wrong, but this causes problems for Farseer. What I'm seeing is that Contact.FixtureA and/or Contact.FixtureB are set to null whilst it's in the middle of iterating and calling the OnCollision handlers (causing null reference exception).

For me it occurs when a bullet hits an enemy and both need to disable their physics at that time, which seems like a common use case. I know I could set a flag to disable the body in the next frame, but I'd rather not.

I've "fixed" it for now by adding Body.Enabled checks in ContactManager.Collide and FixtureA and FixtureB != null checks in Contact.Update(). Perhaps there is a better way though?
Closed Jun 23, 2013 at 1:39 AM by genbox