# 1. Basic syncing

This scene demonstrates the simplest networking scenario possible with **coherence**. Characters sync their position and rotation, which immediately creates a feeling of presence. Someone else is connected!

### **Key controls**

* **WASD** or **Left stick**: Move character
* Hold **Shift** or **Shoulder button left**: Run
* **Spacebar** or **Joypad button down**: Jump

### Topics covered

[CoherenceSync](https://docs.coherence.io/0.10/coherence-sdk-for-unity/components/coherencesync) | Bindings | Component behaviours | [Authority](https://docs.coherence.io/0.10/coherence-sdk-for-unity/authority-overview)

## In this scene...

Upon connecting, the `PlayerHandler` script (attached to the **PlayerHandler** GameObject) creates a new instance of the character Prefab, located in the `Prefabs/Characters` folder. When disconnecting, the same script destroys the instance created.

<figure><img src="https://4229720839-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdBiAEtFeZKdAwRyJ9MEL%2Fuploads%2Fgit-blob-4dfd4bbc51fd7f1510d6f0a478be03941fd68525%2Fimage_030_0000.png?alt=media" alt=""><figcaption><p>A local player meets a network-instantiated player.</p></figcaption></figure>

**coherence** takes care of keeping all Game Clients in sync regarding network entities. When another Client connects, a new instance of your game character is instantiated in their scene, and a copy of their character is instantiated into yours. This is called **network instantiation**.

Now you can move and jump around, and you will see other characters move too.

### How it's set up

You can see what is synced over the network by selecting the Prefab asset, and opening **coherence**'s *Configuration* window (either by clicking on the *Configure* button on the `CoherenceSync` component, or by going to *coherence > GameObject setup > Configure*).

When this window opens on the first tab you will notice that, at the very top, `Transform.position` and `Transform.rotation` are checked.

<figure><img src="https://4229720839-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdBiAEtFeZKdAwRyJ9MEL%2Fuploads%2Fgit-blob-a0ec0f3e8ac0160c3db7f4852ce9e32515c2320a%2FSchermata%202022-12-08%20alle%2015.23.36.png?alt=media" alt=""><figcaption><p>The <em>Variables</em> tab of the <em>Configuration</em> window.</p></figcaption></figure>

{% hint style="info" %}
Are you wondering why the position is checked by default? You'll find answers in the [lesson regarding LiveQueries](https://docs.coherence.io/0.10/learning-coherence/first-steps-tutorial/3-spatial-partitioning).
{% endhint %}

This is the data being transferred over the network. Each Client sends position and rotation of the character they have authority over to every other connected Client, every time there is a change to it that is significant enough. We call these **bindings**.

Each connected Client receives these values and applies them to the `Transform` component of their own instance of the remote player character.

To ensure that Clients don't modify properties of entities they don't have authority on, some components are either disabled or changed on instances that are non-authoritative. If you open the *third tab* of the *Configuration* window, you will see that 3 components are modified:

<figure><img src="https://4229720839-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdBiAEtFeZKdAwRyJ9MEL%2Fuploads%2Fgit-blob-3f024b7224d34247c4724d5c42ddc344b3790044%2FSchermata%202022-12-08%20alle%2015.45.59.png?alt=media" alt=""><figcaption><p>The <em>Components</em> tab of the <em>Configuration</em> window.</p></figcaption></figure>

In particular:

* The `PlayerInput` and `KinematicMove` scripts are disabled.
* The `Rigidbody` component is made kinematic.

### Understanding authority

One important concept to get familiar with is the fact that every networked entity exists as a GameObject on every Client currently connected. However, only one of them has what we call **authority** over the network entity, and can control its synced variables.

For instance, if we play this scene with two Clients, each one will have 2 instances in their respective worlds:

<figure><img src="https://4229720839-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdBiAEtFeZKdAwRyJ9MEL%2Fuploads%2Fgit-blob-483ea94b9e9b308733b819059bc84324f8639fce%2FPerspectives.png?alt=media" alt=""><figcaption><p>A local player character in one Client exists as a remote character on another Client.</p></figcaption></figure>

This is something to keep in mind as you decide which components have to keep running or be disabled on remote instances, in order to not have the same code running unnecessarily on various Clients. This could create a conflict or put the two GameObjects in a very different state, generating unwanted results.

In the Unity Editor, the name of a GameObject and the icon next to it informs you about its current authority state (see image).

{% hint style="warning" %}
There are two types of authority in coherence: **State** and **Input**. For the sake of simplicity, in this project we often refer just to a generic "authority", and what we mean is State authority. Go [here](https://docs.coherence.io/0.10/coherence-sdk-for-unity/authority-overview) for more info on authority.
{% endhint %}

If you want to see which entities are currently local and which ones are remote, we included a debug visualisation in this project. Hit the **Tab** key (or click the Joystick) to switch to a view that shows authority. You can keep playing the game while in this view, and see how things change.

<figure><img src="https://4229720839-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdBiAEtFeZKdAwRyJ9MEL%2Fuploads%2Fgit-blob-64cf451aee6637c4d8be6b14979f26b8c00678ab%2FSchermata%202022-12-08%20alle%2015.31.39.png?alt=media" alt=""><figcaption><p>Blue = local, Orange = remote, the rest are non-networked objects.</p></figcaption></figure>
