Page 1 of 1

removing all entities from space

Posted: Wed Jun 22, 2011 3:30 am
by ron
how to remove all entities from space

Re: removing all entities from space

Posted: Wed Jun 22, 2011 3:33 am
by Norbo
There's no "remove all entities" method. If you want to completely start from scratch, consider disposing the old space and creating a new one. If you want to re-use the space for other reasons, then removing the entities one-by-one is the current best solution. The Space.Entities property exposes the entities currently in the engine.

Re: removing all entities from space

Posted: Wed Jun 22, 2011 4:01 pm
by ron
but disposing does not remove all the entities as i am getting" Cannot add updateable as it already belongs to a space. Ensure that the updateable's space is null before attempting to add it."
after disposing the space

Re: removing all entities from space

Posted: Wed Jun 22, 2011 4:03 pm
by Norbo
Yep, sorry, forgot to mention- if you dispose, it's assuming you're not re-using anything. If you want to re-use something, then you need to do Space.Removes.

Re: removing all entities from space

Posted: Wed Jun 22, 2011 4:04 pm
by ron
like manually removing all the entities?

Re: removing all entities from space

Posted: Wed Jun 22, 2011 4:05 pm
by Norbo
Using Space.Remove, yes.

Re: removing all entities from space

Posted: Wed Jun 22, 2011 4:44 pm
by ron
wht if i do space=null;
Space space;
space=new Space();
space.Add(Entity);
space=null
will it clear the whole space?

Re: removing all entities from space

Posted: Wed Jun 22, 2011 4:50 pm
by Norbo
That creates a new space, adds an entity to the space, and then abandons a reference to the space. The space still exists in memory, unchanged. If you hold a reference to the Entity you added to the Space, you are indirectly holding a reference to the Space, and so the Space will never be collected as garbage. If you did not hold a reference to the Entity and nothing else referred to the Space, then the Space and everything in it (that doesn't have an external reference somewhere) would get finalized at some indeterminate point in the future on the whim of the GC, at which point it is also disposed.

For an example where a space and all of its components are completely killed off, look at the BEPUphysicsDemos. Whenever the simulation switches, the Space is disposed, every single reference to the Space and objects in the Space are lost, and the entire simulation gets garbage collected.

Re: removing all entities from space

Posted: Wed Jun 22, 2011 5:29 pm
by ron
thnks buddy
changing the simulation worked
:)
cheers

Re: removing all entities from space

Posted: Tue Jun 19, 2012 10:22 am
by coimbra79
where the samples source (i found the exe only)

Re: removing all entities from space

Posted: Tue Jun 19, 2012 2:19 pm
by Norbo
The main source download contains the BEPUphysicsDemos project: http://bepuphysics.codeplex.com/SourceC ... changesets