Removing stuff from the World FP3

Topics: Developer Forum, User Forum
Jul 20, 2010 at 11:20 AM
Just a quicky. How do I remove something from the World? Atm I am using these two lines "world.Remove(TheFixture.Body);" and "TheFixture.Body.DestroyFixture(TheFixture);" But the boxes are still there, I can see stuff bouncing off em. Grrr
Jul 20, 2010 at 1:21 PM
Also I cant figure out for the life of me how to set collision groups up. On a Fixture i have three properties "CollidesWith", "CollisionCategories" and "CollisonGroup" none of them seem to effect anything.
Jul 20, 2010 at 1:28 PM

First off, I think you'd better store a reference to the body, not one of it's fixtures. Next, when you remove the body, you don't need to remove the fixture(s) attached to that body manually. For me, just that single line world.Remove(body) works.

Collisiongroups are explained pretty clear in the Farseer 2 documentation if I remember right.

Jul 20, 2010 at 1:34 PM
Its a bit different in FP3. But its ok i got it working. You have to set both "CollidesWith" and "CollisionCategories" which makes sense really. I'll just go try out the body thing;
Jul 20, 2010 at 1:35 PM
world.Remove(body) doesnt seem to work for me, there is still a box reacting with other boxes. hmmmm
Jul 20, 2010 at 2:30 PM
I love talking to myself on here lol. Its the World.Locked thats preventing it. If the engine is midstep it wont let me do anything. I stuck a flag on all the primatives that need destroying and they get cleaned up once the step has completed.
Jul 20, 2010 at 2:32 PM

You're running the world.step() on a different thread?

Jul 20, 2010 at 4:12 PM
No? Just the single plain old thread. I followed the calls in the debugger to the engine to see what the problem was and it was World.Locked returning true.
Jul 20, 2010 at 5:04 PM

Yeah I had this same issue when upgrading to 3.0; 2.1.3 was a little lenient about when you could remove items, so I was lazy and had some items being removed on separate threads.

 

Now I implemented a "Dispose" flag on each item, which gets cleaned up on the physics thread after each step. Much cleaner and reliable.

Jul 20, 2010 at 5:15 PM
Yeah actually I only have one thread but I was doing most stuff on an OnCollision event, I guess under the hood thats done on a seperate thread. We should really bang some document together with some basic snags for new users of FP3
Jul 21, 2010 at 8:04 AM
DrLazer wrote:
Yeah actually I only have one thread but I was doing most stuff on an OnCollision event, I guess under the hood thats done on a seperate thread.

Right, now I understand how you got in 'midstep' :)