CoherenceSyncto your GameObject
GameObject. In this example, we're going to create a Cube.
CoherenceSynccomponent to this Cube.
CoherenceSyncinspector now tells us that we need to make a Prefab out of this
GameObjectfor it to work. We get to choose where to create it.
CoherenceSynccomponent will help you prepare an object for network synchronization during design time. It also exposes an API that allows us to manipulate the object during runtime.
CoherenceSyncwill query all public variables and methods on any of the attached components, for example Unity components such as
Animator, etc. This will include any custom scripts such as
PlayerInputand even scripts that came with the Asset Store packages that you may have downloaded.
Prefab Mapper. The
Prefab Mapperis simply a ScriptableObject that holds Prefabs we want to sync.
CoherenceSyncPrefab outside the Resources folder is not present in the Prefab Mapper, the Add to Prefab Mapper button appears.
Transformsettings: position, rotation, scale.
Move.cs. Copy-paste the following content into the file.
Movescript to the Prefab. This means that if we just run the scene, we will be able to use the keyboard to move the object around.
Movescript will make sure the Component is disabled for network instances of your Prefab.
ComponentActionabstract class, you can implement your own Component Actions.
OnAuthorityThis method will be called when the object is spawned and you have authority over it.
OnRemoteThis method will be called when a remote object is spawned and you do not have authority over it.
ComponentActionclass attribute, specifying the type of Component that you want the Action to work with, and the display name.
CoherenceSynccomponent you can configure settings for Lifetime (
Persistent, Authority transfer (
Steal), Simulation model (
Server Side with Client Input) and Adoption settings for when local persistent entities are orphaned.
On Before Networked Instantiation(before the GameObject is instantiated)
On Networked Instantiation(when the GameObject is instantiated)
On Networked Destruction(when the GameObject is destroyed)
On Authority Gained(when authority over the GameObject is transferred to the local client)
On Authority Lost(when authority over the GameObject is transferred to another client)
On After Authority Transfer Rejected(when GameObject's Authority transfer was requested and denied).
On Input Simulator Connected(when client with simulator is ready for Server-side with Client Input)
On Input Owner Assigned(when InputOwner was changed is ready)
CoherenceSync, hereafter referred to as
Sync Prefabhas one, and only one
CoherenceSynccomponent in its hierarchy
CoherenceSynccomponent must be at the
Sync Prefabcannot contain instances of other
Sync Prefabs. However, such a hierarchy cannot be saved as a
Sync Prefabas that would break rule 1-3.