The state of network entities that are currently not simulated locally (either because they are being simulated on another game client or on a simulator) cannot be affected directly.
Network commands can help us affect state indirectly, but for anything more involved, an authority transfer might be necessary.
In the design phase, CoherenceSync objects can be configured to handle authority transfer in different ways:
Request. Authority transfer may be requested, but it may be rejected by the receiving party.
Steal. Authority will always be given to the requesting party on a FCFS ("first come first serve") basis.
Not transferable. Authority cannot be transferred.
Note also that you need to set up Auto-adopt Orphan if you wan't orphans to be adopted automatically by nearest player.
When using Request, an optional callback OnAuthorityRequestedByConnection
can be set on the CoherenceSync behaviour. If the callback is set, then the results of the callback will override the Approve Requests setting in the behaviour.
The request can be approved or rejected in the callback.
Support for requests based on CoherenceClientConnection.ClientID
is coming soon.
Requesting authority is very straight-forward.
As the transfer is asynchronous, we have to subscribe to one or more Unity Events in CoherenceSync to learn the result.
The request will first go to the replication server and be passed onto the receiving simulator or game client, so it may take a few frames to get a response.
These events are also exposed to the Unity inspector in the Events on authority transfer section of the CoherenceSync behaviour.