Class NetworkBehaviour
The base class to override to write network code. Inherits MonoBehaviour
#
InheritanceSystem.Object
NetworkBehaviour
#
Namespace: Unity.Netcode#
Assembly: MLAPI.dll#
Syntax#
Properties#
HasNetworkObjectGets whether or not this NetworkBehaviour instance has a NetworkObject owner.
#
Declaration#
Property ValueType | Description |
---|---|
System.Boolean |
#
IsClientGets if we are executing as client
#
Declaration#
Property ValueType | Description |
---|---|
System.Boolean |
#
IsHostGets if we are executing as Host, I.E Server and Client
#
Declaration#
Property ValueType | Description |
---|---|
System.Boolean |
#
IsLocalPlayerIf 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.
#
Declaration#
Property ValueType | Description |
---|---|
System.Boolean |
#
IsOwnedByServerGets Whether or not the object has a owner
#
Declaration#
Property ValueType | Description |
---|---|
System.Boolean |
#
IsOwnerGets if the object is owned by the local player or if the object is the local player object
#
Declaration#
Property ValueType | Description |
---|---|
System.Boolean |
#
IsServerGets if we are executing as server
#
Declaration#
Property ValueType | Description |
---|---|
System.Boolean |
#
IsSpawnedUsed 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
#
Declaration#
Property ValueType | Description |
---|---|
System.Boolean |
#
NetworkBehaviourIdGets NetworkId for this NetworkBehaviour from the owner NetworkObject
#
Declaration#
Property ValueType | Description |
---|---|
System.UInt16 |
#
NetworkManagerGets the NetworkManager that owns this NetworkBehaviour instance See
note around NetworkObject
for how there is a chicken / egg problem
when we are not initialized
#
Declaration#
Property ValueType | Description |
---|---|
NetworkManager |
#
NetworkObjectGets the NetworkObject that owns this NetworkBehaviour instance.
#
Declaration#
Property ValueType | Description |
---|---|
NetworkObject |
#
NetworkObjectIdGets the NetworkId of the NetworkObject that owns this NetworkBehaviour
#
Declaration#
Property ValueType | Description |
---|---|
System.UInt64 |
#
OwnerClientIdGets the ClientId that owns the NetworkObject
#
Declaration#
Property ValueType | Description |
---|---|
System.UInt64 |
#
Methods#
GetNetworkBehaviour(UInt16)Returns a the NetworkBehaviour with a given BehaviourId for the current NetworkObject
#
Declaration#
ParametersType | Name | Description |
---|---|---|
System.UInt16 | behaviourId | The behaviourId to return |
#
ReturnsType | Description |
---|---|
NetworkBehaviour | Returns NetworkBehaviour with given behaviourId |
#
GetNetworkObject(UInt64)Gets the local instance of a object with a given NetworkId
#
Declaration#
ParametersType | Name | Description |
---|---|---|
System.UInt64 | networkId |
#
ReturnsType | Description |
---|---|
NetworkObject |
#
OnDestroy()Invoked when the the NetworkBehaviour is attached to. NOTE: If you override this, you will want to always invoke this base class version of this OnDestroy() method!!
#
Declaration#
OnGainedOwnership()Gets called when the local client gains ownership of this object
#
Declaration#
OnLostOwnership()Gets called when we loose ownership of this object
#
Declaration#
OnNetworkDespawn()Gets called when the NetworkObject gets despawned. Is called both on the server and clients.
#
Declaration#
OnNetworkObjectParentChanged(NetworkObject)Gets called when the parent NetworkObject of this NetworkBehaviour's NetworkObject has changed
#
Declaration#
ParametersType | Name | Description |
---|---|---|
NetworkObject | parentNetworkObject | the new NetworkObject parent |
#
OnNetworkSpawn()Gets called when the NetworkObject gets spawned, message handlers are ready to be registered and the network is setup.