docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class GhostObject

    Bridge class between your GameObject and the underlying Netcode ghost entity. This is your main access point to the underlying ghost's data. It'll be in charge of initializing your GameObject's ghost and keeping it in sync with the underlying ghost.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    BaseGhostSettings
    GhostObject
    Inherited Members
    BaseGhostSettings.HasOwner
    BaseGhostSettings.SupportAutoCommandTarget
    BaseGhostSettings.TrackInterpolationDelay
    BaseGhostSettings.GhostGroup
    BaseGhostSettings.UsePreSerialization
    BaseGhostSettings.UseSingleBaseline
    BaseGhostSettings.RollbackPredictedSpawnedGhostState
    BaseGhostSettings.RollbackPredictionOnStructuralChanges
    BaseGhostSettings.ForcePrefabConversion
    BaseGhostSettings.DefaultGhostMode
    BaseGhostSettings.SupportedGhostModes
    BaseGhostSettings.OptimizationMode
    BaseGhostSettings.Importance
    BaseGhostSettings.MaxSendRate
    BaseGhostSettings.SnapshotHistorySize
    BaseGhostSettings.FullTickSmoothing
    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.destroyCancellationToken
    MonoBehaviour.useGUILayout
    MonoBehaviour.didStart
    MonoBehaviour.didAwake
    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, bool)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>(bool)
    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.GetComponentIndex()
    Component.CompareTag(string)
    Component.CompareTag(TagHandle)
    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.transformHandle
    Component.gameObject
    Component.tag
    Object.GetEntityId()
    Object.GetInstanceID()
    Object.Equals(object)
    Object.InstantiateAsync<T>(T)
    Object.InstantiateAsync<T>(T, Transform)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int)
    Object.InstantiateAsync<T>(T, int, Transform)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, CancellationToken)
    Object.InstantiateAsync<T>(T, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, Vector3, Quaternion, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion, InstantiateParameters, CancellationToken)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, InstantiateParameters, CancellationToken)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Scene)
    Object.Instantiate<T>(T, InstantiateParameters)
    Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
    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.FindObjectsOfType(Type, bool)
    Object.FindObjectsByType(Type, FindObjectsSortMode)
    Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)
    Object.FindObjectsByType(Type)
    Object.FindObjectsByType(Type, FindObjectsInactive)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, float)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectsByType<T>(FindObjectsSortMode)
    Object.FindObjectsOfType<T>(bool)
    Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
    Object.FindObjectOfType<T>()
    Object.FindObjectOfType<T>(bool)
    Object.FindFirstObjectByType<T>()
    Object.FindAnyObjectByType<T>()
    Object.FindFirstObjectByType<T>(FindObjectsInactive)
    Object.FindAnyObjectByType<T>(FindObjectsInactive)
    Object.FindObjectsByType<T>()
    Object.FindObjectsByType<T>(FindObjectsInactive)
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.FindFirstObjectByType(Type)
    Object.FindAnyObjectByType(Type)
    Object.FindObjectOfType(Type, bool)
    Object.FindFirstObjectByType(Type, FindObjectsInactive)
    Object.FindAnyObjectByType(Type, FindObjectsInactive)
    Object.name
    Object.hideFlags
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Netcode
    Assembly: Unity.NetCode.dll
    Syntax
    [DisallowMultipleComponent]
    [DefaultExecutionOrder(-2147483647)]
    [AddComponentMenu("Multiplayer/Ghost Object", 50)]
    public sealed class GhostObject : BaseGhostSettings
    Remarks

    This uses Netcode for Entities to create a ghost entity for your GameObject. The pattern is similar to a Rigidbody associated with a GameObject. The rigidbody will have its own representation in an internal physics world and will match with its GameObject counterpart.

    Fields

    GhostTransform

    The current non-smoothed, tick-accurate transform attached to this ghost.

    Declaration
    [NonSerialized]
    public GhostComponentRef<LocalTransform> GhostTransform
    Field Value
    Type Description
    GhostComponentRef<LocalTransform>

    SkipAutomaticPrefabRegistration

    Prefabs are automatically tracked by Netcode. However this means once a prefab is registered, its settings can't be modified anymore. In order to programmatically update those settings, you need to make sure to update them before prefab registration. This setting allows you to control when prefab registration happens. Make sure to call RegisterPrefab(GameObject, NetcodeWorld) yourself.

    Declaration
    [Tooltip("Prefabs are automatically tracked by Netcode. However this means once a prefab is registered, its settings can't be modified anymore. In order to programmatically update those settings, you need to make sure to update them before prefab registration. This setting allows you to control when prefab registration happens. Make sure to call Netcode.RegisterPrefab yourself.")]
    [SerializeField]
    public bool SkipAutomaticPrefabRegistration
    Field Value
    Type Description
    bool

    UseUniformScale

    By default, GhostObject ghosts support (and replicate) non-uniform (per-axis) 3D scale, stored in a PostTransformMatrix component on the ghost entity. Enable this to treat the scale as uniform instead: no PostTransformMatrix is added, and the scale is driven by Unity.Transforms.LocalTransform.Scale (taken from transform.localScale.x; y and z are ignored). Saves the PostTransformMatrix chunk memory and its per-snapshot change bit on ghosts that never scale non-uniformly.

    Declaration
    [Tooltip("By default, GhostObject ghosts support (and replicate) non-uniform (per-axis) 3D scale, stored in a PostTransformMatrix component on the ghost entity.\n\nEnable this to treat the scale as uniform instead: no PostTransformMatrix is added, and the scale is driven by LocalTransform.Scale (taken from transform.localScale.x; y and z are ignored).\n\nSaves the PostTransformMatrix chunk memory and its per-snapshot change bit on ghosts that never scale non-uniformly.")]
    [SerializeField]
    public bool UseUniformScale
    Field Value
    Type Description
    bool

    Properties

    CanWriteState

    Whether this ghost is being predicted. See PredictedGhost.

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

    DelaySpawning

    By default, instantiating an object will immediately spawn that object to all clients. Set this field to true to delay spawning the object. Once this object is Instantiated, you will need to manually call Spawn() to spawn this object.

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

    Entity

    The underlying generated ghost Unity.Entities.Entity associated with this GameObject. Updating the GhostObject's data will update the entity's data which will then be synchronized using Netcode for Entities.

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

    GhostId

    The networked ID for this ghost, shared across the network. ghostId Assigned before OnGhostSpawn() on the server and on client ghosts spawned from the network. A client predicted spawn has no ID until the server confirms it; reading it before that throws. GhostInfo exposes the raw value (0 while unassigned). If you plan to use other fields like SpawnTick or GhostType consider using GhostInfo instead for better batched performance

    Declaration
    public int GhostId { get; }
    Property Value
    Type Description
    int

    GhostInfo

    Various metadata associated with this ghost. GhostInstance

    Declaration
    public GhostInstance GhostInfo { get; }
    Property Value
    Type Description
    GhostInstance

    GhostType

    The ghost type (which prefab) was used to spawn this ghost. ghostType If you plan to use other fields like SpawnTick or GhostId consider using GhostInfo instead for better batched performance

    Declaration
    public int GhostType { get; }
    Property Value
    Type Description
    int

    IsClient

    Whether this ghost is spawned in a client world.

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

    IsServer

    Whether this ghost is spawned in a server world.

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

    IsSpawned

    Whether this ghost is currently spawned and linked to its entity.

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

    OwnerNetworkId

    The NetworkId of the owner of this ghost. Only valid if HasOwner is true.

    Declaration
    public NetworkId OwnerNetworkId { get; set; }
    Property Value
    Type Description
    NetworkId

    ParentReplication

    When true, the parent of this GhostObject will be replicated to clients.
    When false (the default), the parent will not be replicated and the OnParentChanged event will not be invoked. Ghost parenting is prediction compatible: a client can parent a ghost that is predicting, and the authority overrides it. A client cannot parent a ghost that is interpolating.

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

    Position

    The current non-smoothed, tick-accurate position (in local space) of the ghost.

    Declaration
    public Vector3 Position { get; set; }
    Property Value
    Type Description
    Vector3

    Rotation

    The current non-smoothed position (in local space) of the ghost. The ghost and gameobject transform may not be necessarily in sync (i.e when switching prediction mode, when smoothing host ghosts or with prediction error smoothing).

    Declaration
    public Quaternion Rotation { get; set; }
    Property Value
    Type Description
    Quaternion

    SpawnTick

    The tick at which this ghost was spawn. spawnTick If you plan to use other fields like GhostId or GhostType consider using GhostInfo instead for better batched performance

    Declaration
    public NetworkTick SpawnTick { get; }
    Property Value
    Type Description
    NetworkTick

    World

    The world this ghost belongs to. Can be a client or server world

    Declaration
    public NetcodeWorld World { get; }
    Property Value
    Type Description
    NetcodeWorld

    Methods

    Despawn()

    Despawns this GhostObject and destroys the associated GameObject it on all connected clients.

    Declaration
    public void Despawn()
    Remarks

    This function is only valid to be used if DelaySpawning is set to true. Otherwise, this object can only be despawned from the network by destroying this GhostObject.

    GetHashCode()

    Value-based hash of all serialized ghost settings edited via the authoring inspector. Used to detect whether an inspector edit actually changed a setting (a clamped drag can leave the value unchanged), so we only trigger a re-bake when something really changed.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int

    A hash of all serialized ghost settings.

    Overrides
    BaseGhostSettings.GetHashCode()

    PublishTransform()

    Takes the tick-accurate transform and applies it to the transform

    Declaration
    public void PublishTransform()

    Spawn()

    Spawns this GhostObject across the network.

    Declaration
    public void Spawn()
    Remarks

    This function is only valid to be used if DelaySpawning is set to true. Otherwise, this object will be automatically spawned over the network when the object is instantiated.

    Events

    OnParentChanged

    Event that is invoked when a valid parent of this GhostObject changes. Only triggers when ParentReplication is enabled.

    Declaration
    public event Action<Transform, Transform> OnParentChanged
    Event Type
    Type Description
    Action<Transform, Transform>
    Remarks

    When this event is triggered it will provide the previous parent and the new parent Transform as parameters.
    Parenting can be cancelled by Netcode when invalid, which means MonoBehaviour parenting changed events can be later reverted. Use this callback for when you want to make sure a parenting change actually happened.

    Extension Methods

    GhostObjectPredictionSwitchExtension.ConvertToInterpolated(GhostObject, float)
    GhostObjectPredictionSwitchExtension.ConvertToPredicted(GhostObject, float)
    In This Article
    Back to top
    Copyright © 2026 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)