Setting Body.Enabled=false in OnCollision not supported

Topics: User Forum
Feb 16, 2013 at 5:49 PM
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?
Coordinator
Feb 18, 2013 at 4:28 AM
For now, I would recommend you set a flag that they have hit each other, and then take action after the world step is finished.
I will copy this to an issue and take a look at how this can be improved in the future.
Coordinator
Feb 18, 2013 at 4:28 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.