Class NetworkBehaviour
The base class to override to write network code. Inherits MonoBehaviour
Inherited Members
Namespace: Unity.Netcode
Assembly: solution.dll
Syntax
public abstract class NetworkBehaviour : MonoBehaviour
Properties
Name | Description |
---|---|
HasNetworkObject | Gets whether or not this NetworkBehaviour instance has a NetworkObject owner. |
IsClient | Gets if we are executing as client |
IsHost | Gets if we are executing as Host, I.E Server and Client |
IsLocalPlayer | If a NetworkObject is assigned, it will return whether or not this NetworkObject is the local player object. If no NetworkObject is assigned it will always return false. |
IsOwnedByServer | Gets Whether or not the object has a owner |
IsOwner | Gets if the object is owned by the local player or if the object is the local player object |
IsServer | Gets if we are executing as server |
IsSpawned | Used to determine if it is safe to access NetworkObject and NetworkManager from within a NetworkBehaviour component Primarily useful when checking NetworkObject/NetworkManager properties within FixedUpate |
NetworkBehaviourId | Gets NetworkId for this NetworkBehaviour from the owner NetworkObject |
NetworkManager | Gets the NetworkManager that owns this NetworkBehaviour instance
See note around |
NetworkObject | Gets the NetworkObject that owns this NetworkBehaviour instance |
NetworkObjectId | Gets the NetworkId of the NetworkObject that owns this NetworkBehaviour |
OwnerClientId | Gets the ClientId that owns the NetworkObject |
m_TargetIdBeingSynchronized | The relative client identifier targeted for the serialization of this NetworkBehaviour instance. |
Methods
Name | Description |
---|---|
GetNetworkBehaviour(ushort) | Returns a the NetworkBehaviour with a given BehaviourId for the current NetworkObject |
GetNetworkObject(ulong) | Gets the local instance of a object with a given NetworkId |
OnDestroy() | Invoked when the GameObject the NetworkBehaviour is attached to. NOTE: If you override this, you will want to always invoke this base class version of this OnDestroy() method!! |
OnGainedOwnership() | Gets called when the local client gains ownership of this object |
OnLostOwnership() | Gets called when we loose ownership of this object |
OnNetworkDespawn() | Gets called when the NetworkObject gets despawned. Is called both on the server and clients. |
OnNetworkObjectParentChanged(NetworkObject) | Gets called when the parent NetworkObject of this NetworkBehaviour's NetworkObject has changed |
OnNetworkSpawn() | Gets called when the NetworkObject gets spawned, message handlers are ready to be registered and the network is setup. |
OnOwnershipChanged(ulong, ulong) | Invoked on all clients, override this method to be notified of any ownership changes (even if the instance was niether the previous or newly assigned current owner). |
OnSynchronize<T>(ref BufferSerializer<T>) | Override this method if your derived NetworkBehaviour requires custom synchronization data. Note: Use of this method is only for the initial client synchronization of NetworkBehaviours and will increase the payload size for client synchronization and dynamically spawned NetworkObjects. |