librelist archives

« back to archive

Removing Components from an Entity

Removing Components from an Entity

From:
David Wicks
Date:
2013-09-02 @ 18:57
Hello,

First off, I'm enjoying using entityx to explore entity system concepts. 
I've been able to rewrite a simple 2d renderer to be cleaner and faster by
using components, which is great.

To speed up the renderer, I am cacheing all the render components it uses 
into a list (a std::vector). When new render components are added I add 
them to the list and when entities die I remove their render components 
from the list. Once this was set up, I realized that an entity could shed 
a component without itself being destroyed. Or at least I thought it 
should be able to.

In the public API, I wasn't able to find any way to remove a component 
from an entity. On a related note, once (and if) that is possible, there 
should be an associated ComponentRemovedEvent<T>.

Is there a way to remove components from an entity? Or will there be?

The only viable way I've found of doing that so far is quite a kludge 
(copy all things to preserve to a new Entity):
Entity new_entity = entity_manager->create();
// for each preserved component...
auto component = old_entity.component<Component>();
old_entity.destroy();
// attach preserved components to new entity
new_entity.assign( component );

Thanks,
David
______________
David Wicks
sansumbrella.com

Re: Removing Components from an Entity

From:
David Wicks
Date:
2013-09-02 @ 20:11
I just submitted a pull request that provides the remove() functionality I expect.

I'm not familiar with gtest, so I haven't written tests for the methods.

-David
______________
David Wicks
sansumbrella.com




On Sep 2, 2013, at 2:57 PM, David Wicks <wicks.db@gmail.com> wrote:

> Hello,
> 
> First off, I'm enjoying using entityx to explore entity system concepts.
I've been able to rewrite a simple 2d renderer to be cleaner and faster by
using components, which is great.
> 
> To speed up the renderer, I am cacheing all the render components it 
uses into a list (a std::vector). When new render components are added I 
add them to the list and when entities die I remove their render 
components from the list. Once this was set up, I realized that an entity 
could shed a component without itself being destroyed. Or at least I 
thought it should be able to.
> 
> In the public API, I wasn't able to find any way to remove a component 
from an entity. On a related note, once (and if) that is possible, there 
should be an associated ComponentRemovedEvent<T>.
> 
> Is there a way to remove components from an entity? Or will there be?
> 
> The only viable way I've found of doing that so far is quite a kludge 
(copy all things to preserve to a new Entity):
> Entity new_entity = entity_manager->create();
> // for each preserved component...
> auto component = old_entity.component<Component>();
> old_entity.destroy();
> // attach preserved components to new entity
> new_entity.assign( component );
> 
> Thanks,
> David
> ______________
> David Wicks
> sansumbrella.com
> 

Re: [entityx] Re: Removing Components from an Entity

From:
Alec Thomas
Date:
2013-09-03 @ 01:58
Excellent! 

Thanks David, I've merged the pull request (after adding some tests). 


On Monday, September 2, 2013 at 4:11 PM, David Wicks wrote:

> I just submitted a pull request that provides the remove() functionality
I expect.
> 
> I'm not familiar with gtest, so I haven't written tests for the methods.
> 
> -David
> ______________
> David Wicks
> sansumbrella.com (http://sansumbrella.com)
> 
> 
> 
> 
> 
> 
> On Sep 2, 2013, at 2:57 PM, David Wicks <wicks.db@gmail.com 
(mailto:wicks.db@gmail.com)> wrote:
> > Hello,
> > 
> > First off, I'm enjoying using entityx to explore entity system 
concepts. I've been able to rewrite a simple 2d renderer to be cleaner and
faster by using components, which is great.
> > 
> > To speed up the renderer, I am cacheing all the render components it 
uses into a list (a std::vector). When new render components are added I 
add them to the list and when entities die I remove their render 
components from the list. Once this was set up, I realized that an entity 
could shed a component without itself being destroyed. Or at least I 
thought it should be able to.
> > 
> > In the public API, I wasn't able to find any way to remove a component
from an entity. On a related note, once (and if) that is possible, there 
should be an associated ComponentRemovedEvent<T>.
> > 
> > Is there a way to remove components from an entity? Or will there be?
> > 
> > The only viable way I've found of doing that so far is quite a kludge 
(copy all things to preserve to a new Entity):
> > Entity new_entity = entity_manager->create();
> > // for each preserved component...
> > auto component = old_entity.component<Component>();
> > old_entity.destroy();
> > // attach preserved components to new entity
> > new_entity.assign( component );
> > 
> > Thanks,
> > David
> > ______________
> > David Wicks
> > sansumbrella.com (http://sansumbrella.com/)
> > 
> > 
> > 
>