PDA

View Full Version : Entity component model



Stoney
20-12-2011, 07:22 AM
Hi guys,
I'm in the progress of tackling another itch in my engine which is the entity component model. At the moment it works like this: You create an entity and must attach a node (the visual representation of an object in a scene) to it. You can then create one or multiple components, add them to an entity and the components will be updated each frame. You can even send messages from components, and technically communicate between components. It works in general, but I still have some reservations to use it in a bigger project.

My ideas/thoughts:
- De-coupling the node from the entity; Basically nodes should then be components and you could plug them on entities; Advantage: More flexibility, but that requires me to rewrite some node related stuff and this forces me to have a render procedure in a component which I personally would like to avoid
- Using generics for inheritance: Basically entities could inherit from T which could either be a node or prefab entities (like say TMoveableEntity or TEntityWithHealthAndWeapons); I'm not so sure if that's a good idea though as the point of the entity component model is to try to use as little inheritance as possible on game objects
- I came across the Artemis framework (http://gamadu.com/artemis/). Basically their idea behind this is to get rid of all the logic in components (no render or update calls) and components act like data stores. This is a good approach in my opinion, but I'm not sure I like the systems idea in it and this would probably be the most complex one to adopt.

I would like to know from anyone who has an entity component model in their game/engine how you chose to implement it or which idea you would like best.

User137
20-12-2011, 10:55 AM
I haven't done this kind myself yet, but just some thoughts. What i imagine is that, when i want to for example put a hat on a character model, it will have access to all bones in that model. Bones themselves would not store any extra data but the hat would know the object and bone index it's attached to.

I just need a simple model format with bones and animations -.-

Stoney
20-12-2011, 04:38 PM
The entity component model does not necessarily mean, that it's an actual 3D model. For more about what an entity component model is, see this blog post: http://piemaster.net/2011/07/entity-component-primer/

I think the best way to go to communicate between components is a messaging system which allows the component to "talk" with its parent entity, like MyEntity.SendMessage('Heya, all my little component') or MyEntity.SendMessage('Hi, specific component', ComponentInstance) and from the component side something along like MyComponent.DidReceiveMessage('Heya, all my little components'). This is how I implemented it already and it is very similar to how this is handled in Unity3D.
Because you don't really know which components your entity has, I think sending messages is the best way, even though it may impact the performance a bit.

paul_nicholls
20-12-2011, 07:50 PM
The entity component model does not necessarily mean, that it's an actual 3D model. For more about what an entity component model is, see this blog post: http://piemaster.net/2011/07/entity-component-primer/

I think the best way to go to communicate between components is a messaging system which allows the component to "talk" with its parent entity, like MyEntity.SendMessage('Heya, all my little component') or MyEntity.SendMessage('Hi, specific component', ComponentInstance) and from the component side something along like MyComponent.DidReceiveMessage('Heya, all my little components'). This is how I implemented it already and it is very similar to how this is handled in Unity3D.
Because you don't really know which components your entity has, I think sending messages is the best way, even though it may impact the performance a bit.

I see that article above is I guess about the "Strategy Pattern", like in this one:

http://obviam.net/index.php/design-in-game-entities-object-composition-strategies-part-1/

I think I would like to do objects like that, but I just haven't gotten around to it yet LOL

cheers,
Paul