removing all entities from space

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

removing all entities from space

Post by ron »

how to remove all entities from space
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: removing all entities from space

Post 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.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: removing all entities from space

Post 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
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: removing all entities from space

Post 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.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: removing all entities from space

Post by ron »

like manually removing all the entities?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: removing all entities from space

Post by Norbo »

Using Space.Remove, yes.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: removing all entities from space

Post by ron »

wht if i do space=null;
Space space;
space=new Space();
space.Add(Entity);
space=null
will it clear the whole space?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: removing all entities from space

Post 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.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: removing all entities from space

Post by ron »

thnks buddy
changing the simulation worked
:)
cheers
coimbra79
Posts: 33
Joined: Thu Dec 29, 2011 12:42 am

Re: removing all entities from space

Post by coimbra79 »

where the samples source (i found the exe only)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: removing all entities from space

Post by Norbo »

The main source download contains the BEPUphysicsDemos project: http://bepuphysics.codeplex.com/SourceC ... changesets
Post Reply