Conditional Query?

For example:
I have a game where 100000000 black flys live in the forest. Normally each fly sits and does nothing, but if there is a man is in the forest, all flys should start following him and try to bite him.

So I need a system that does 2 things:

  • check if man exists (query for the entity with [man] component and its [position])
  • and if the man was found iterates on all flys and call MoveTowards(man.position) function

the problem is with “if”, how to make a conditional query?
if the man isn’t in the forest, the second costly query should not happen

Best idea I have is to split it into 2 systems: CheckForManSystem and MoveFlysSystem
and to make CheckForManSystem enable/disable MoveFlysSystem

What is the best way to organize this behavior in ECS?
Is it possible to skip the second query using only one system?

Why complicate it, single system with a requirement on the man query to run

this.RequireForUpdate(manQuery);

or

this.RequireSingletonForUpdate();

if there is only ever a maximum of 1 man.

2 Likes

wow, I’ve missed a moment when RequireForUpdate and singleton methods were added

Perfect, thank you, works like a charm )

1 Like