Unity.Netcode.NetworkBehaviour
The base class to override to write network code. Inherits MonoBehaviour
#
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 TODO: this needs an overhaul. It's expensive, it's ja little naive in how it looks for networkObject in its parent and worst, it creates a puzzle if you are a NetworkBehaviour wanting to see if you're live or not (e.g. editor code). All you want to do is find out if NetworkManager is null, but to do that you need NetworkObject, but if you try and grab NetworkObject and NetworkManager isn't up you'll get the warning below. This is why IsBehaviourEditable had to be created. Matt was going to re-do how NetworkObject works but it was close to the release and too risky to change
#
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()#
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 |
#
OnNetworkSpawn()Gets called when the NetworkObject gets spawned, message handlers are ready to be registered and the network is setup.