Another design question, or is it good to have a Not(EntityComponent) filter

Beside the usual mistakes i made when designe my game logic i often want a Not (Entity does not have EntityComponent) filter. The question is if that is again a hint of a bad design, and if yes, how to ship around.

Usecase:

[java]

WeaponSystem:

TargetVector{
Vector3f target;
}

Systems i would like to have:

RotateEntityToTarget{
ComponentsRequired: someComponents,TargetVector.class
}
This is working as expected.

RotateEntityToRestPosition{
ComponetsRequired: someComponents, RestPosition.class,
RequiredFilters: Not(TargetVector.class)
}
[/java]

Basically i would use the ā€˜Notā€™ filter in this case to optain a set of entities which do not have a TargetVector componentā€¦

Valid design, or failed to see a simple alternative?

Not having a component is not a valid ā€œstateā€ for a system. It would collect every entity in the whole universe whether you really wanted to or not. I mean, presumably you are detecting on some other set of components and I wonder why that isnā€™t enough.

In your example, what if you someday decide to have other positions other than targeting and rest? Now you need to go hunt down all of the cases that are fighting you because you sucked in the whole world. Seems like maybe you are missing a component rather than trying to detect a ā€˜notā€™.

Taking a step back even further, TargetVector and RestPosition might even be too specific. One Facing component could cover every entity that ever needed to look in any direction. Whether facing is ā€œto a targetā€ or ā€œto restā€ is a matter of game logic. Maybe you have some entity that wants to keep looking in its target direction after the target goes away. A Facing component covers this case alsoā€¦ since the only way you get to rest is through some game logic that sets Facing to a rest orientation. It could choose not to.

1 Like

Looking at it another way, exactly what is it targeting and why? Thatā€™s the missing pieceā€¦ the system that decides to target something and untarget it.

Point takenā€¦ have to think about it before i make a followup post

Ok, after thinking about it during the work afternoon i think i found my concept issue. My goal actually was to have something like a default behaviour if nothing special is specified. And it seems that is not possible actually.

@zzuegg said: Ok, after thinking about it during the work afternoon i think i found my concept issue. My goal actually was to have something like a default behaviour if nothing special is specified. And it seems that is not possible actually.

Well, the default behavior could be applied by the thing that notices that the object was removed from some entity set.

Alternately, the default behavior is still indicated by a component. Iā€™d have to know more about your use-case to comment betterā€¦ like all ā€˜actorsā€™ involved in these components (producing and consuming).