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).