menu_bookDocumentation
NetworkSpawn, Ownership Transfer, and Network.Refresh in s&box
NetworkSpawn and Ownership Transfer in s&box
Spawning a Networked Object
CSHARP
// Spawn with local connection as owner
go.NetworkSpawn();
// Spawn with a specific owner
go.NetworkSpawn( someConnection );
// Spawn with full options
go.NetworkSpawn( new NetworkSpawnOptions
{
Owner = someConnection,
StartEnabled = true,
OrphanedMode = NetworkOrphaned.Host,
OwnerTransfer = OwnerTransfer.Takeable,
Flags = NetworkFlags.NoInterpolation,
AlwaysTransmit = false
} );Ownership Transfer Modes (OwnerTransfer)
| Value | Behavior |
|---|---|
| Fixed | Only the host can change ownership |
| Takeable | Any client can take ownership freely |
| Request | Clients must request ownership from the host |
Taking and Dropping Ownership
CSHARP
// Take ownership (respects OwnerTransfer mode)
go.Network.TakeOwnership();
// Assign to a specific connection
go.Network.AssignOwnership( connection );
// Drop ownership (object becomes host-controlled)
go.Network.DropOwnership();Checking Ownership
CSHARP
bool isOwner = go.Network.IsOwner;
bool isProxy = go.Network.IsProxy;
bool isCreator = go.Network.IsCreator;
Connection owner = go.Network.Owner; // null if unownedNetwork Refresh
After making structural changes (adding/removing components or child GameObjects), call Refresh() to sync the full state to all clients:
CSHARP
go.Network.Refresh(); // full refresh
go.Network.Refresh( someDescendant ); // refresh a specific child
go.Network.Refresh( someComponent ); // refresh a specific componentAlwaysTransmit
By default AlwaysTransmit = true. When false, the engine uses PVS (Potentially Visible Set) and bounds-based culling to skip sending updates to connections that can't see the object. Objects must be invisible for 2 seconds before culling kicks in.
Was this helpful?