Skip to main content

Unity.Netcode.NetworkObjectReference

A helper struct for serializing NetworkObjects over the network. Can be used in RPCs and NetworkVariable\<T>.

Implements#

INetworkSerializable

System.IEquatable\<NetworkObjectReference>

Inherited Members#

ValueType.ToString()

Object.Equals(Object, Object)

Object.GetType()

Object.ReferenceEquals(Object, Object)

Namespace: System.Dynamic.ExpandoObject#
Assembly: MLAPI.dll#
Syntax#
public struct NetworkObjectReference : INetworkSerializable, IEquatable<NetworkObjectReference>

NetworkObjectReference(GameObject)#

Creates a new instance of the NetworkObjectReference struct.

Declaration#

public NetworkObjectReference(GameObject gameObject)

Parameters#

TypeNameDescription
GameObjectgameObjectThe GameObject from which the NetworkObject component will be referenced.

Exceptions#

TypeCondition
System.ArgumentNullException
System.ArgumentException

NetworkObjectReference(NetworkObject)#

Creates a new instance of the NetworkObjectReference struct.

Declaration#

public NetworkObjectReference(NetworkObject networkObject)

Parameters#

TypeNameDescription
NetworkObjectnetworkObjectThe NetworkObject to reference.

Exceptions#

TypeCondition
System.ArgumentNullException
System.ArgumentException

#

NetworkObjectId#

The NetworkObjectId of the referenced NetworkObject.

Declaration#

public ulong NetworkObjectId { get; }

Property Value#

TypeDescription
System.UInt64

#

Equals(Object)#

Declaration#

public override bool Equals(object obj)

Parameters#

TypeNameDescription
System.Objectobj

Returns#

TypeDescription
System.Boolean

Overrides#

System.ValueType.Equals(System.Object)

Equals(NetworkObjectReference)#

Declaration#

public bool Equals(NetworkObjectReference other)

Parameters#

TypeNameDescription
NetworkObjectReferenceother

Returns#

TypeDescription
System.Boolean

GetHashCode()#

Declaration#

public override int GetHashCode()

Returns#

TypeDescription
System.Int32

Overrides#

System.ValueType.GetHashCode()

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#

TypeNameDescription
BufferSerializer\<T>serializerThe serializer to use to read and write the data.

Type Parameters#

NameDescription
TEither BufferSerializerReader or BufferSerializerWriter, depending whether the serializer is in read mode or write mode.

TryGet(out NetworkObject, NetworkManager)#

Tries to get the NetworkObject referenced by this reference.

Declaration#

public bool TryGet(out NetworkObject networkObject, NetworkManager networkManager = null)

Parameters#

TypeNameDescription
NetworkObjectnetworkObjectThe NetworkObject which was found. Null if no object was found.
NetworkManagernetworkManagerThe networkmanager. Uses Singleton to resolve if null.

Returns#

TypeDescription
System.BooleanTrue if the NetworkObject was found; False if the NetworkObject was not found. This can happen if the NetworkObject has not been spawned yet. you can try getting the reference at a later point in time.

#

Implicit(GameObject to NetworkObjectReference)#

Declaration#

public static implicit operator NetworkObjectReference(GameObject gameObject)

Parameters#

TypeNameDescription
GameObjectgameObject

Returns#

TypeDescription
NetworkObjectReference

Implicit(NetworkObject to NetworkObjectReference)#

Declaration#

public static implicit operator NetworkObjectReference(NetworkObject networkObject)

Parameters#

TypeNameDescription
NetworkObjectnetworkObject

Returns#

TypeDescription
NetworkObjectReference

Implicit(NetworkObjectReference to GameObject)#

Declaration#

public static implicit operator GameObject(NetworkObjectReference networkObjectRef)

Parameters#

TypeNameDescription
NetworkObjectReferencenetworkObjectRef

Returns#

TypeDescription
GameObject

Implicit(NetworkObjectReference to NetworkObject)#

Declaration#

public static implicit operator NetworkObject(NetworkObjectReference networkObjectRef)

Parameters#

TypeNameDescription
NetworkObjectReferencenetworkObjectRef

Returns#

TypeDescription
NetworkObject

Implements#

INetworkSerializable

System.IEquatable\<T>