docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class GhostBehaviour

    The base class for all Monobehaviours in need to access Ghost features.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    GhostBehaviour
    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.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.MemberwiseClone()
    Object.GetInstanceID()
    Object.GetHashCode()
    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
    public abstract class GhostBehaviour : MonoBehaviour

    Properties

    CanWriteState

    Check to make sure you can write to your ghost's data. Should be true when on the authority (server) or when predicting on any client. This can be on your local owner client or on other clients predicting you.

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

    Ghost

    Access to the Ghost for this GhostBehaviour. Only valid after the object is fully spawned and initialized. This is the "bridge" between GameObject and entities and the main point of access for Netcode features.

    Declaration
    public GhostObject Ghost { get; }
    Property Value
    Type Description
    GhostObject

    IsClient

    Whether this ghost lives in a client world.

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

    IsServer

    Whether this ghost lives in a server world.

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

    Methods

    Awake()

    Unity message that registers this behaviour with its GhostObject. Overrides must call the base implementation.

    Declaration
    public virtual void Awake()

    GetComponentTypes()

    Returns the ECS component types backing this behaviour's ghost data. Overridden by source generators.

    Declaration
    protected virtual IEnumerable<ComponentType> GetComponentTypes()
    Returns
    Type Description
    IEnumerable<ComponentType>

    The component types to add to the ghost entity.

    InitializeComponentRef<T>(ref GhostComponentRef<T>, bool)

    Initializes the given GhostComponentRef. This is called by source generators and shouldn't be called manually

    Declaration
    protected void InitializeComponentRef<T>(ref GhostComponentRef<T> field, bool withInitialValue) where T : unmanaged, IComponentData
    Parameters
    Type Name Description
    GhostComponentRef<T> field

    The component reference to initialize.

    bool withInitialValue

    determines if Initialization should use the serialized InitialValue

    Type Parameters
    Name Description
    T

    The component type referenced.

    InitializeGhostField<T>(ref GhostField<T>, ComponentType, bool)

    Initializes the given GhostField. This is called by source generators and shouldn't be called manually

    Declaration
    protected void InitializeGhostField<T>(ref GhostField<T> field, ComponentType type, bool withInitialValue) where T : unmanaged
    Parameters
    Type Name Description
    GhostField<T> field

    The field to initialize.

    ComponentType type

    The generated component type backing the field.

    bool withInitialValue

    determines if Initialization should use the serialized InitialValue

    Type Parameters
    Name Description
    T

    The unmanaged value type of the field.

    InitializeGhostInput<T>(ref GhostInput<T>, bool)

    Initializes the given GhostInput. This is called by source generators and shouldn't be called manually

    Declaration
    protected void InitializeGhostInput<T>(ref GhostInput<T> field, bool withInitialValue) where T : unmanaged, IInputComponentData
    Parameters
    Type Name Description
    GhostInput<T> field

    The input to initialize.

    bool withInitialValue

    determines if Initialization should use the serialized InitialValue

    Type Parameters
    Name Description
    T

    The input component type.

    InitializeRuntimeGameObject(bool)

    Links this behaviour's ghost data to the runtime entity. Overridden by source generators.

    Declaration
    protected virtual void InitializeRuntimeGameObject(bool withInitialValue)
    Parameters
    Type Name Description
    bool withInitialValue

    Whether to apply the serialized initial values to the entity components.

    OnGhostDespawn()

    Invoked when the GhostObject gets despawned or destroyed. This method runs both client and server side.

    Declaration
    public virtual void OnGhostDespawn()

    OnGhostSpawn()

    Invoked when the GhostObject gets spawned, the related Entity is linked, and the Network has finished being set-up.

    Declaration
    public virtual void OnGhostSpawn()
    Remarks

    Invoked before this GhostBehaviour's Awake(): the GhostObject spawns the ghost from its own Awake, which runs first. When DelaySpawning is set to true, OnGhostSpawn() will be invoked when Spawn() is called. GhostId is already assigned here, except for client predicted spawns.

    PredictionGatherInput(PredictionGatherInputContext)

    Override this method to gather your inputs for prediction.

    Declaration
    public virtual void PredictionGatherInput(PredictionGatherInputContext context)
    Parameters
    Type Name Description
    PredictionGatherInputContext context

    Context for the input gathering of the current frame.

    Remarks

    This runs in your frame from the GhostInputSystemGroup group.

    Declare your input as a GhostInput<TInput> field and follow its PrepareToCapture() / Capture(in TInput) flow. See GhostInput<TInput> for the details.

    Here are some reasons why gathering inputs from this method is recommended:

    • This method will only get called on clients and on the ghosts the client owns, before the prediction loop. This ensures there's minimal latency between when an input is detected and the associated network command is sent to the server. It also helps reduce the potential for mispredictions.
    • Prediction will modify your inputs to adapt to the current tick it's simulating when rolling back and replaying. You can't gather inputs from prediction.
    • If your owner switches, that owner switch gets applied in a system executing before input gathering. If you try to update your inputs from Update() (which executes before all SimulationGroup systems), you'd get a value for GhostOwnerIsLocal that's not updated yet, but will be for prediction when it runs. Same for new spawns.
    • With forced input latency (ForcedInputLatencyTicks) or without partial ticks (FullTicksOnly, the default), Netcode writes the latest input stored in the command buffer back into your input struct right before this method, so changes made outside of this method are overwritten.

    PredictionPhysicsUpdate(PredictionPhysicsUpdateContext)

    Override this to implement predicted logic that interacts with predicted physics.

    Declaration
    public virtual void PredictionPhysicsUpdate(PredictionPhysicsUpdateContext context)
    Parameters
    Type Name Description
    PredictionPhysicsUpdateContext context

    Context for predicted physics.

    PredictionUpdate(PredictionUpdateContext)

    Override this to implement your own prediction logic. To access current predicted deltaTime, use context. To access other time related information, use Time. See "Introduction to Prediction" and other various articles in the manual for more details on prediction.

    Declaration
    public virtual void PredictionUpdate(PredictionUpdateContext context)
    Parameters
    Type Name Description
    PredictionUpdateContext context

    Context for the predicted tick being simulated.

    Remarks

    With FullTicksOnly this is only called on full ticks, like the rest of the PredictedSimulationSystemGroup. Visual smoothness between ticks is then handled by FullTickSmoothing, the same smoothing a single-world host uses. Enabling partial ticks project wide (PartialTickModeSelection) also calls this on partial ticks (NetworkTime.IsPartialTick), with a TickedDeltaTime that is a fraction of the tick. Full ticks only does not mean TickedDeltaTime is constant: with prediction step batching (MaxPredictionStepBatchSizeRepeatedTick), rollback resimulation can batch multiple ticks into a single call, with a delta time that is a multiple of the simulation tick delta time.

    TearDownComponentRef<T>(ref GhostComponentRef<T>)

    Tears down the given GhostComponentRef. This is called by source generators and shouldn't be called manually

    Declaration
    protected void TearDownComponentRef<T>(ref GhostComponentRef<T> field) where T : unmanaged, IComponentData
    Parameters
    Type Name Description
    GhostComponentRef<T> field

    The component reference to tear down.

    Type Parameters
    Name Description
    T

    The component type referenced.

    TearDownGhostField<T>(ref GhostField<T>)

    Tears down the given GhostField. This is called by source generators and shouldn't be called manually

    Declaration
    protected void TearDownGhostField<T>(ref GhostField<T> field) where T : unmanaged
    Parameters
    Type Name Description
    GhostField<T> field

    The field to tear down.

    Type Parameters
    Name Description
    T

    The unmanaged value type of the field.

    TearDownGhostInput<T>(ref GhostInput<T>)

    Tears down the given GhostInput. This is called by source generators and shouldn't be called manually

    Declaration
    protected void TearDownGhostInput<T>(ref GhostInput<T> field) where T : unmanaged, IInputComponentData
    Parameters
    Type Name Description
    GhostInput<T> field

    The input to tear down.

    Type Parameters
    Name Description
    T

    The input component type.

    TearDownRuntimeGameObject()

    Unlinks this behaviour's ghost data from the runtime entity. Overridden by source generators.

    Declaration
    protected virtual void TearDownRuntimeGameObject()
    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)