Struct NetworkBehaviourReference
A helper struct for serializing NetworkBehaviours over the network. Can be used in RPCs and NetworkVariable<T>. Note: network ids get recycled by the NetworkManager after a while. So a reference pointing to
Inherited Members
Namespace: Unity.Netcode
Assembly: solution.dll
Syntax
public struct NetworkBehaviourReference : INetworkSerializable, IEquatable<NetworkBehaviourReference>
Constructors
NetworkBehaviourReference(NetworkBehaviour)
Creates a new instance of the NetworkBehaviourReference<T> struct.
Declaration
public NetworkBehaviourReference(NetworkBehaviour networkBehaviour)
Parameters
Type | Name | Description |
---|---|---|
NetworkBehaviour | networkBehaviour | The NetworkBehaviour to reference. |
Exceptions
Type | Condition |
---|---|
ArgumentException |
Methods
Equals(object)
Indicates whether this instance and a specified object are equal.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current instance. |
Returns
Type | Description |
---|---|
bool | true if |
Overrides
Equals(NetworkBehaviourReference)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(NetworkBehaviourReference other)
Parameters
Type | Name | Description |
---|---|---|
NetworkBehaviourReference | other | An object to compare with this object. |
Returns
Type | Description |
---|---|
bool | true if the current object is equal to the |
GetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A 32-bit signed integer that is the hash code for this instance. |
Overrides
NetworkSerialize<T>(BufferSerializer<T>)
Provides bi-directional serialization to read and write the desired data to serialize this type.
Declaration
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
Parameters
Type | Name | Description |
---|---|---|
BufferSerializer<T> | serializer | The serializer to use to read and write the data. |
Type Parameters
Name | Description |
---|---|
T | Either BufferSerializerReader or BufferSerializerWriter, depending whether the serializer is in read mode or write mode. |
TryGet(out NetworkBehaviour, NetworkManager)
Tries to get the NetworkBehaviour referenced by this reference.
Declaration
public bool TryGet(out NetworkBehaviour networkBehaviour, NetworkManager networkManager = null)
Parameters
Type | Name | Description |
---|---|---|
NetworkBehaviour | networkBehaviour | The NetworkBehaviour which was found. Null if the corresponding NetworkObject was not found. |
NetworkManager | networkManager | The networkmanager. Uses Singleton to resolve if null. |
Returns
Type | Description |
---|---|
bool | True if the NetworkBehaviour was found; False if the NetworkBehaviour was not found. This can happen if the corresponding NetworkObject has not been spawned yet. you can try getting the reference at a later point in time. |
TryGet<T>(out T, NetworkManager)
Tries to get the NetworkBehaviour referenced by this reference.
Declaration
public bool TryGet<T>(out T networkBehaviour, NetworkManager networkManager = null) where T : NetworkBehaviour
Parameters
Type | Name | Description |
---|---|---|
T | networkBehaviour | The NetworkBehaviour which was found. Null if the corresponding NetworkObject was not found. |
NetworkManager | networkManager | The networkmanager. Uses Singleton to resolve if null. |
Returns
Type | Description |
---|---|
bool | True if the NetworkBehaviour was found; False if the NetworkBehaviour was not found. This can happen if the corresponding NetworkObject has not been spawned yet. you can try getting the reference at a later point in time. |
Type Parameters
Name | Description |
---|---|
T | The type of the networkBehaviour for convenience. |
Operators
implicit operator NetworkBehaviourReference(NetworkBehaviour)
Implicitly convert NetworkBehaviour to NetworkBehaviourReference.
Declaration
public static implicit operator NetworkBehaviourReference(NetworkBehaviour networkBehaviour)
Parameters
Type | Name | Description |
---|---|---|
NetworkBehaviour | networkBehaviour | The NetworkBehaviour to convert from. |
Returns
Type | Description |
---|---|
NetworkBehaviourReference | The NetworkBehaviourReference created from the NetworkBehaviour passed in as a parameter |
implicit operator NetworkBehaviour(NetworkBehaviourReference)
Implicitly convert NetworkBehaviourReference to NetworkBehaviour.
Declaration
public static implicit operator NetworkBehaviour(NetworkBehaviourReference networkBehaviourRef)
Parameters
Type | Name | Description |
---|---|---|
NetworkBehaviourReference | networkBehaviourRef | The NetworkBehaviourReference to convert from. |
Returns
Type | Description |
---|---|
NetworkBehaviour | The NetworkBehaviour this class is holding a reference to |