Areas of Interest
Last updated
Last updated
Areas of interest (or 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.
At the moment, coherence offers two ways to express this interest: LiveQuery and TagQuery.
With LiveQueries the filtering is volume-based, kind of like moving a torch to look around in a dark cave.
With TagQueries even distant objects can be seen, provided they have the right tag.
You need at least one query in your scene, or you won't see anything update over the network.
When a non-authoritative object falls outside of all queries, it gets destroyed (or returned to an object pool). When it gets back in, it gets reinstantiated (or taken out of the pool). If the right properties are synced, the object's state will be automatically restored by coherence, making the player feel like that object never disappeared.
Queries only filter network entities that are non-authoritative. Your own entities will never be destroyed for falling outside of a query.
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.
It is a very common pattern to move a LiveQuery around, following a player character or the camera, to ensure the visible objects are updated.
In addition to this, queries can be turned on/off (simply by disabling the GameObject that hosts 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 per-Client, meaning that each Client (or Simulator!) has its own queries and thus sees different parts of the simulation.
Queries can also be used for cheat prevention, see Server authoritative setup for more information.