For the complete documentation index, see llms.txt. This page is also available as Markdown.

Queries

Queries are not only a way to optimise, but a fundamental tool for Clients to specify what part(s) of the online world they are interested in.

With them, the Replication Server can filter the information to send based on each Client's interest, and thus greatly optimise network traffic.

In the left window, Player2 is not visible because it's outside of Player1's LiveQueries

At the moment, coherence offers three ways to filter network entities: Live Query, Tag Query and Global Query.

  • With Live Queries the filtering is volume-based, kind of like moving a torch to look around in a dark cave.

  • With Tag Queries even distant entities can be seen, provided they have the right Tag.

  • With Global Queries any entities marked as Is Global can be seen.

When a non-authoritative entity falls outside of all queries, it gets destroyed (or returned to an object pool). When it gets back in, it gets re-instantiated (or taken out of the pool). If the right properties are synced, the entity's state will be automatically restored by coherence, making the player feel like that entity never disappeared.

Queries only filter network entities that are non-authoritative. Your own entities will never be destroyed for falling outside of a query.

Queries are additive

When using queries and adding more than one, they act in an additive way.

So for instance, two overlapping LiveQueries will define a bigger area.

Similarly, a LiveQuery + a TagQuery will add up, looking for entities both within a range but also for the ones that have a certain tag, regardless of position.

Non-additive filtering will come in a future version of coherence.

Runtime changes

It is a very common pattern to move a LiveQuery around, following a player character or the camera, to ensure the visible entities are updated.

In addition to this, queries can be turned on/off (simply by disabling them), or their properties can be changed at runtime (like radius, position, or tag), making for a very dynamic tool to optimise bandwidth.

Queries are personal

Queries are per-Client, meaning that each Client (or Simulator!) has its own queries and thus sees different parts of the simulation.

Was this helpful?