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

FPE 3.0 Best Way to Clear World

Aug 31, 2010 at 12:35 PM

In FPE 2, there was a Clear() method that would remove all bodies, joints, etc. from the engine.

It would be nice if that existed for FPE 3.0.  

Without that, what is the best way to clear the world?

My thought is to just spin through each of the lists, joint, body, controller... and call "RemoveXXX".  I think I'll probably need to spin through each list backward to avoid index issues.

Is there a better way to do this?


Aug 31, 2010 at 2:23 PM
Edited Aug 31, 2010 at 2:30 PM

Might be faster just to create a new World and let the GC clean up the old one, since that would be instantaneous. I don't see a benefit to keeping the old World that wouldn't be overtaken by the cost of clearing everything.


ClearGameEntities(); // clear any game-specific classes that might hold a reference to something in world
world = new World(Gravity);
GC.Collect(); // assuming you're at a "pause" point if you're clearing the world.


Aug 31, 2010 at 11:05 PM

Yes, this is actually what ended up doing shortly after posting my question. Works well.