# Authority transfer

### Overview

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 ](/0.4.14/authority/commands.md)and [events ](broken://pages/-MYOiFgzwqMr4bcgd4Wz)can help us affect state indirectly, but for anything more involved, an authority transfer might be necessary.

### Types of Authority Transfer

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 (i.e. when *Approve requests* is false).
* **Steal.** Authority will always be given to the requesting party on a FCFS ("first come first serve") basis.
* **Not transferable**. Authority cannot be transferred.

<div align="left"><img src="/files/-MYg4DscnE8e9YZ3fLdm" alt=""></div>

### Requesting Authority in Code

Requesting authority is very straight-forward.

```csharp
var coherenceSync = target.GetComponent<CoherenceSync>();
coherenceSync.RequestAuthority();
```

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.

```csharp
// There Unity Events in CoherenceSync help us understand 
// what happened with authority requests and act accordingly.

public UnityEvent OnAuthorityTransferRejected;

// TRUE is authority is transfered being gained, FALSE if lost
public UnityEvent<bool> OnBeforeAuthorityTransfer;

// TRUE is authority is transfered being gained, FALSE if lost
public UnityEvent<bool> OnAfterAuthorityTransfer;
```


---

# Agent Instructions: 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/0.4.14/authority/authority-transfer.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.
