docs.unity3d.com
    Show / Hide Table of Contents

    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
    ValueType.ToString()
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetType()
    Namespace: Unity.Netcode
    Syntax
    public struct NetworkBehaviourReference : INetworkSerializable, IEquatable<NetworkBehaviourReference>

    Constructors

    NetworkBehaviourReference(NetworkBehaviour)

    Creates a new instance of the struct.

    Declaration
    public NetworkBehaviourReference(NetworkBehaviour networkBehaviour)
    Parameters
    Type Name Description
    NetworkBehaviour networkBehaviour

    The NetworkBehaviour to reference.

    Exceptions
    Type Condition
    ArgumentException

    Methods

    Equals(Object)

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    Object obj
    Returns
    Type Description
    Boolean
    Overrides
    ValueType.Equals(Object)

    Equals(NetworkBehaviourReference)

    Declaration
    public bool Equals(NetworkBehaviourReference other)
    Parameters
    Type Name Description
    NetworkBehaviourReference other
    Returns
    Type Description
    Boolean
    Implements
    IEquatable<T>.Equals(T)

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32
    Overrides
    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
    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.

    Implements
    INetworkSerializable.NetworkSerialize<T>(BufferSerializer<T>)

    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
    Boolean

    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
    Boolean

    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(NetworkBehaviour to NetworkBehaviourReference)

    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(NetworkBehaviourReference to NetworkBehaviour)

    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

    In This Article
    • Constructors
      • NetworkBehaviourReference(NetworkBehaviour)
    • Methods
      • Equals(Object)
      • Equals(NetworkBehaviourReference)
      • GetHashCode()
      • NetworkSerialize<T>(BufferSerializer<T>)
      • TryGet(out NetworkBehaviour, NetworkManager)
      • TryGet<T>(out T, NetworkManager)
    • Operators
      • Implicit(NetworkBehaviour to NetworkBehaviourReference)
      • Implicit(NetworkBehaviourReference to NetworkBehaviour)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023