docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class NetworkObject

    A component used to identify that a GameObject in the network

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    NetworkObject
    Inherited Members
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(string, float)
    MonoBehaviour.InvokeRepeating(string, float, float)
    MonoBehaviour.CancelInvoke(string)
    MonoBehaviour.IsInvoking(string)
    MonoBehaviour.StartCoroutine(string)
    MonoBehaviour.StartCoroutine(string, object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StartCoroutine_Auto(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(string)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(object)
    MonoBehaviour.useGUILayout
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, out Component)
    Component.TryGetComponent<T>(out T)
    Component.GetComponent(string)
    Component.GetComponentInChildren(Type, bool)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(bool)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, bool)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(bool)
    Component.GetComponentsInChildren<T>(bool, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, bool)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(bool)
    Component.GetComponentsInParent<T>(bool, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.CompareTag(string)
    Component.SendMessageUpwards(string, object, SendMessageOptions)
    Component.SendMessageUpwards(string, object)
    Component.SendMessageUpwards(string)
    Component.SendMessageUpwards(string, SendMessageOptions)
    Component.SendMessage(string, object)
    Component.SendMessage(string)
    Component.SendMessage(string, object, SendMessageOptions)
    Component.SendMessage(string, SendMessageOptions)
    Component.BroadcastMessage(string, object, SendMessageOptions)
    Component.BroadcastMessage(string, object)
    Component.BroadcastMessage(string)
    Component.BroadcastMessage(string, SendMessageOptions)
    Component.transform
    Component.gameObject
    Component.tag
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(object)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, bool)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, bool)
    Object.Destroy(Object, float)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, bool)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, float)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectOfType<T>()
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.ToString()
    Object.name
    Object.hideFlags
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: MLAPI
    Assembly: Unity.Multiplayer.MLAPI.Runtime.dll
    Syntax
    [AddComponentMenu("MLAPI/NetworkObject", -99)]
    [DisallowMultipleComponent]
    public sealed class NetworkObject : MonoBehaviour

    Fields

    AlwaysReplicateAsRoot

    If true, the object will always be replicated as root on clients and the parent will be ignored.

    Declaration
    public bool AlwaysReplicateAsRoot
    Field Value
    Type Description
    bool

    CheckObjectVisibility

    Delegate invoked when the MLAPI needs to know if the object should be visible to a client, if null it will assume true

    Declaration
    public NetworkObject.VisibilityDelegate CheckObjectVisibility
    Field Value
    Type Description
    NetworkObject.VisibilityDelegate

    DontDestroyWithOwner

    Whether or not to destroy this object if it's owner is destroyed. If false, the objects ownership will be given to the server.

    Declaration
    public bool DontDestroyWithOwner
    Field Value
    Type Description
    bool

    IncludeTransformWhenSpawning

    Delegate invoked when the MLAPI needs to know if it should include the transform when spawning the object, if null it will assume true

    Declaration
    public NetworkObject.SpawnDelegate IncludeTransformWhenSpawning
    Field Value
    Type Description
    NetworkObject.SpawnDelegate

    NetworkInstanceId

    InstanceId is the id that is unique to the object and scene for a scene object when UsePrefabSync is false. If UsePrefabSync is true or if it's used on non scene objects, this has no effect. Should not be set manually

    Declaration
    [HideInInspector]
    [SerializeField]
    public ulong NetworkInstanceId
    Field Value
    Type Description
    ulong

    PrefabHash

    The Prefab unique hash. This should not be set my the user but rather changed by editing the PrefabHashGenerator. It has to be the same for all instances of a prefab

    Declaration
    [HideInInspector]
    [SerializeField]
    public ulong PrefabHash
    Field Value
    Type Description
    ulong

    PrefabHashGenerator

    The generator used to change the PrefabHash. This should be set the same for all instances of a prefab. It has to be unique in relation to other prefabs

    Declaration
    [SerializeField]
    public string PrefabHashGenerator
    Field Value
    Type Description
    string

    Properties

    DestroyWithScene

    Gets whether or not the object should be automatically removed when the scene is unloaded.

    Declaration
    public bool DestroyWithScene { get; }
    Property Value
    Type Description
    bool

    IsLocalPlayer

    Gets if the object is the the personal clients player object

    Declaration
    public bool IsLocalPlayer { get; }
    Property Value
    Type Description
    bool

    IsOwnedByServer

    Gets Whether or not the object is owned by anyone

    Declaration
    public bool IsOwnedByServer { get; }
    Property Value
    Type Description
    bool

    IsOwner

    Gets if the object is owned by the local player or if the object is the local player object

    Declaration
    public bool IsOwner { get; }
    Property Value
    Type Description
    bool

    IsPlayerObject

    Gets if this object is a player object

    Declaration
    public bool IsPlayerObject { get; }
    Property Value
    Type Description
    bool

    IsSceneObject

    Gets if the object is a SceneObject, null if it's not yet spawned but is a scene object.

    Declaration
    public bool? IsSceneObject { get; }
    Property Value
    Type Description
    bool?

    IsSpawned

    Gets if the object has yet been spawned across the network

    Declaration
    public bool IsSpawned { get; }
    Property Value
    Type Description
    bool

    NetworkManager

    Gets the NetworkManager that owns this NetworkObject instance

    Declaration
    public NetworkManager NetworkManager { get; }
    Property Value
    Type Description
    NetworkManager

    NetworkObjectId

    Gets the unique Id of this object that is synced across the network

    Declaration
    public ulong NetworkObjectId { get; }
    Property Value
    Type Description
    ulong

    OwnerClientId

    Gets the ClientId of the owner of this NetworkObject

    Declaration
    public ulong OwnerClientId { get; }
    Property Value
    Type Description
    ulong

    Methods

    ChangeOwnership(ulong)

    Changes the owner of the object. Can only be called from server

    Declaration
    public void ChangeOwnership(ulong newOwnerClientId)
    Parameters
    Type Name Description
    ulong newOwnerClientId

    The new owner clientId

    Despawn(bool)

    Despawns this GameObject and destroys it for other clients. This should be used if the object should be kept on the server

    Declaration
    public void Despawn(bool destroy = false)
    Parameters
    Type Name Description
    bool destroy

    GetObservers()

    Returns Observers enumerator

    Declaration
    public HashSet<ulong>.Enumerator GetObservers()
    Returns
    Type Description
    HashSet<ulong>.Enumerator

    Observers enumerator

    IsNetworkVisibleTo(ulong)

    Whether or not this object is visible to a specific client

    Declaration
    public bool IsNetworkVisibleTo(ulong clientId)
    Parameters
    Type Name Description
    ulong clientId

    The clientId of the client

    Returns
    Type Description
    bool

    True if the client knows about the object

    NetworkHide(List<NetworkObject>, ulong)

    Hides a list of objects from a client

    Declaration
    public static void NetworkHide(List<NetworkObject> networkObjects, ulong clientId)
    Parameters
    Type Name Description
    List<NetworkObject> networkObjects

    The objects to hide

    ulong clientId

    The client to hide the objects from

    NetworkHide(ulong)

    Hides a object from a specific client

    Declaration
    public void NetworkHide(ulong clientId)
    Parameters
    Type Name Description
    ulong clientId

    The client to hide the object for

    NetworkShow(List<NetworkObject>, ulong, Stream)

    Shows a list of previously hidden objects to a client

    Declaration
    public static void NetworkShow(List<NetworkObject> networkObjects, ulong clientId, Stream payload = null)
    Parameters
    Type Name Description
    List<NetworkObject> networkObjects

    The objects to show

    ulong clientId

    The client to show the objects to

    Stream payload

    An optional payload to send as part of the spawns

    NetworkShow(ulong, Stream)

    Shows a previously hidden object to a client

    Declaration
    public void NetworkShow(ulong clientId, Stream payload = null)
    Parameters
    Type Name Description
    ulong clientId

    The client to show the object to

    Stream payload

    An optional payload to send as part of the spawn

    RemoveOwnership()

    Removes all ownership of an object from any client. Can only be called from server

    Declaration
    public void RemoveOwnership()

    Spawn(Stream, bool)

    Spawns this GameObject across the network. Can only be called from the Server

    Declaration
    public void Spawn(Stream spawnPayload = null, bool destroyWithScene = false)
    Parameters
    Type Name Description
    Stream spawnPayload

    The writer containing the spawn payload

    bool destroyWithScene

    Should the object be destroyd when the scene is changed

    SpawnAsPlayerObject(ulong, Stream, bool)

    Spawns an object across the network and makes it the player object for the given client

    Declaration
    public void SpawnAsPlayerObject(ulong clientId, Stream spawnPayload = null, bool destroyWithScene = false)
    Parameters
    Type Name Description
    ulong clientId

    The clientId whos player object this is

    Stream spawnPayload

    The writer containing the spawn payload

    bool destroyWithScene

    Should the object be destroyd when the scene is changed

    SpawnWithOwnership(ulong, Stream, bool)

    Spawns an object across the network with a given owner. Can only be called from server

    Declaration
    public void SpawnWithOwnership(ulong clientId, Stream spawnPayload = null, bool destroyWithScene = false)
    Parameters
    Type Name Description
    ulong clientId

    The clientId to own the object

    Stream spawnPayload

    The writer containing the spawn payload

    bool destroyWithScene

    Should the object be destroyd when the scene is changed

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)