menu_bookDocumentation
Network Ownership: Taking, Dropping, and Transferring Object Control
Networked GameObjects can be owned by a connection. Objects owned by a connection are simulated by that connection — their position and sync variables are controlled by the owning client. Unowned objects are simulated by the host.
Owner Transfer
By default, only the host can change ownership. The current owner can change this:
CSHARP
go.Network.SetOwnerTransfer( OwnerTransfer.Takeover );| Type | Behaviour |
|---|---|
| OwnerTransfer.Takeover | Anyone can change the owner |
| OwnerTransfer.Fixed (default) | Only the host can change the owner |
| OwnerTransfer.Request | A request must be made to the host |
Checking Ownership
Use IsProxy to check if the object is simulated by someone else:
CSHARP
protected override void OnUpdate()
{
if ( IsProxy ) return; // controlled by someone else
if ( Input.Pressed( "use" ) )
TryPickup();
}Taking and Dropping Ownership
CSHARP
// Take ownership (you become the simulator)
go.Network.TakeOwnership();
// Drop ownership (host takes over)
go.Network.DropOwnership();Disconnection (Orphaned Mode)
Control what happens to owned objects when a client disconnects:
CSHARP
GameObject.Network.SetOrphanedMode( NetworkOrphaned.Host );| Type | Behaviour |
|---|---|
| NetworkOrphaned.Destroy (default) | Object destroyed when owner disconnects |
| NetworkOrphaned.Host | Host gets ownership |
| NetworkOrphaned.Random | Random client gets ownership |
| NetworkOrphaned.ClearOwner | Object remains, host simulates |
Was this helpful?