This project has moved and is read-only. For the latest updates, please go here.

EndContact events fire only for the last registered object

Topics: Developer Forum, User Forum
Feb 21, 2012 at 6:03 PM

Here's my situation:

I have several objects that contain a body and a fixture. They are set to sensor = true;

atmosphere = BodyFactory.CreateCircle(world, atmosphereRadius / Level.METER_IN_PIXELS, 1f, new Vector2(pos.X, pos.Y));
atmosphere.IsSensor = true;
//JointFactory.CreateWeldJoint(world, this.getBody(), atmosphere, getBody().LocalCenter, atmosphere.LocalCenter);

this.registerBeginContact(new BeginContactDelegate(this.OnBeginContact));
.registerEndContact(new EndContactDelegate(this.OnEndContact));

I commented out the join part because it didn't seem to make a difference either way. When the object we control goes enters any of these bodies, the even its fired properly. However, when the player object leaves the sensor field, it doesn't fire the OnEndContact method, EXCEPT if it was the last object that I call

this.registerEndContact(new EndContactDelegate(this.OnEndContact));

When my OnEndContact method is called by the EndContact event in ContactManager, it is called for ALL the delegates I registered, including the ones that are tied to the objects that are not getting these events to fire. The OnBeginContact delegates work perfectly, firing for every object, but the EndContact event does not.

Does anyone have any idea why this is happening or is this a bug in Farseer?

for reference my register methods look like this

public void registerBeginContact(BeginContactDelegate action)
      getLevel().getWorld().ContactManager.BeginContact += action;
public void registerEndContact(EndContactDelegate action)
    getLevel().getWorld().ContactManager.EndContact += action;

Thanks in advance.