Systems with optional Components

65 views
Skip to first unread message

That Guy

unread,
Dec 19, 2014, 9:18:55 AM12/19/14
to ash-fr...@googlegroups.com
An example:

A Knight has a number of components, SpatialComponent, SpriteComponent, HealthComponent etc....
One of his components is a DestinationComponent. It is required by a number of Systems, such as the PathingSystem, which determines where the Knight will wander too.

The Knight can be hit on the head, and forget where he is trying to get to. The simplest option would be to remove the DestinationComponent from the Knight Entity.
The removes him from the PathingSystem, so he wont move anywhere.

But I want him to wander around the map, not simply stand still. Most of the code for this is already in the PathingSystem, so I'd like the wandering functionality to be part of the PathingSystem. If I remove the DestinationComponent from the PathingNode, then for every PathingNode I'd have to check if it has the DestinationComponent. I'd rather avoid this overhead (no, don't know how much it is, it can't be great though, I have lots of nodes to process).


So, would I have to maintain an extra collection of Nodes for this? One for those with the DestinationComponent, and one for those without it?

Daniel Krejčí

unread,
Dec 19, 2014, 5:49:55 PM12/19/14
to ash-fr...@googlegroups.com
It would be probably wiser to have separate Node for wandering entities and maybe even create separate system for that. Depends what it your wandering about, like walking in random directions around or generating random location that is further away? In that case you could use your DestinationComponent and have WanderingComponent just to mark that the knight is wandering and once he arrives to destination, generate new one for him.

Eric Lund

unread,
Dec 19, 2014, 7:37:17 PM12/19/14
to ash-fr...@googlegroups.com
I'd probably add a ConfusionComponent to the knight entity and a ConfusionSystem that runs before the PathingSystem. The ConfusionSystem should randomly alter the destination value in the DestinationComponent by some relative amount when the entity is newly confused or its path was recently reached. Using a distinct system for applying confusion means 1) your PathingSystem can stick to just pathing, and 2) if no entities are confused no time is wasted processing optional components.

This puts me pretty much in agreement with Daniel's second case, although I'm more advocating a separation of concerns.
Reply all
Reply to author
Forward
0 new messages