> For the complete documentation index, see [llms.txt](https://docs.coherence.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coherence.io/2.3/getting-started/samples-and-tutorials/first-steps-tutorial/3-spatial-partitioning.md).

# 3. Live Queries

Getting updates about every entity in the whole scene is unfeasible for big-world games, like MMOs. For this, **coherence** has a flexible system for filtering entities in your scene based on where they are located, using a tool component called [Live Query](/2.3/manual/components/coherence-live-query.md).

{% tabs %}
{% tab title="Topics covered" %}
[LiveQuery](/2.3/manual/components/coherence-live-query.md) | [Optimization](/2.3/manual/optimization.md)
{% endtab %}

{% tab title="Game controls" %}

* **WASD** or **Left stick**: Move character
* Hold **Shift** or **Shoulder button left**: Run
* **Spacebar** or **Joypad button down**: Jump
  {% endtab %}
  {% endtabs %}

## In this scene

This scene contains two cubes that represent volumes where we want network synchronization to happen. Every connected Client can only see other players if they are standing inside one of these cubes.

<figure><img src="/files/6hVrgVMZUivkmn8TfjIy" alt=""><figcaption><p>Player2 can see Player1 (because they are within a Live Query), but not the opposite.</p></figcaption></figure>

## How it's set up

Select one of the two GameObjects named **LiveQuery**. You will see they have a CoherenceLiveQuery component:

<figure><img src="/files/PWaibQadDb2TGfrk47le" alt=""><figcaption></figcaption></figure>

This component defines an valume (in this case a 10x10x10 cube, 5 is the **Extent**). This is telling the Replication Server that this Client is only interested in network entities that are physically present within this volume.

If a Client has to know about the whole world, set the Live Query to **Infinite**.

{% hint style="success" %}
Now it's clear why `Transform.position` cannot be excluded from synchronization, as we saw in [the first lesson](/2.3/getting-started/samples-and-tutorials/first-steps-tutorial/1-basic-syncing.md). **coherence** needs to know where network entities are in space at all times, to detect if they fall within a Live Query or not.
{% endhint %}

Live Queries can move in space. They can be parented to the camera, to the player, or to other moving elements.

It is also possible, like in this scene, to have more than one Live Query. They will act as additive, requesting updates from entities that are within at least one of the volumes.

Notice that at least one Live Query is needed: a Client with no Live Query in the scene will receive no updates at all.

{% hint style="info" %}
If you explored previous scenes you might have noticed that GameObjects with a Live Query component were actually there, but in this scene we gave them a special visual representation, just for demo purposes.
{% endhint %}

### Not just visibility

Try moving in and out of volumes. You will notice that network-instantiation takes care of destroying the GameObject representing a remote entity that exits a Live Query, and reinstantiates it when it enters one again.

Also, notice that the player belonging to the local Client doesn't disappear. **coherence** will stop sending updates about this instance to other Clients, but the instance is not destroyed locally, as long as the Client retains authority on it.

{% hint style="warning" %}
If a GameObject can be in a state that needs to be computed somehow, it might not appear correctly in the instant it gets recreated.

For instance, an animation state machine might not be in the correct animation state if it had previously reached that state via a trigger parameter. You would have to ensure that the trigger is called again when the instance gets network-instantiated (via a [Network Command](/2.3/getting-started/samples-and-tutorials/first-steps-tutorial/1-basic-syncing/1-3-sending-commands.md)) or switch your state machine to use other type of animation parameters, which would be automatically synced as soon as the entity gets reinstantiated.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.coherence.io/2.3/getting-started/samples-and-tutorials/first-steps-tutorial/3-spatial-partitioning.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
