menu_bookDocumentation
IGameObjectNetworkEvents: Ownership Change and Control Transfer Events
IGameObjectNetworkEvents lets Components on a networked GameObject react to ownership changes. The events are targeted only at the specific GameObject whose ownership is changing.
Interface
CSHARP
public interface IGameObjectNetworkEvents : ISceneEvent<IGameObjectNetworkEvents>
{
void NetworkOwnerChanged( Connection newOwner, Connection previousOwner ) { }
void StartControl() { }
void StopControl() { }
}Events
| Method | When Called |
|---|---|
| NetworkOwnerChanged | Owner of the networked object changes. Provides both new and previous Connection. |
| StartControl | This client has become the controller (no longer a proxy). |
| StopControl | This object has become a proxy (controlled by someone else). |
Usage Example
CSHARP
public sealed class OwnershipTracker : Component, IGameObjectNetworkEvents
{
void IGameObjectNetworkEvents.StartControl()
{
// We now control this object — enable input handling
Log.Info( "We took control!" );
}
void IGameObjectNetworkEvents.StopControl()
{
// Someone else controls this now — disable input
Log.Info( "Lost control, now a proxy" );
}
void IGameObjectNetworkEvents.NetworkOwnerChanged( Connection newOwner, Connection previousOwner )
{
Log.Info( $"Owner changed from {previousOwner?.DisplayName} to {newOwner?.DisplayName}" );
}
}When to Use
- Enabling/disabling input handling when ownership transfers
- Updating UI to reflect who controls an object
- Triggering effects when a player picks up or drops an object
- Cleaning up state when losing control of a vehicle or weapon
Was this helpful?