docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct GhostInput<TInput>

    Declares the input of a ghost and guides how to capture it. Each PredictionGatherInput(PredictionGatherInputContext), start from PrepareToCapture(), fill the returned struct with what is active this frame, then hand it over with Capture(in TInput). Netcode sends the captured input at regular intervals to the server and replays it during prediction, where GetForCurrentTick() returns the input for the simulated tick.

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Netcode
    Assembly: Unity.NetCode.dll
    Syntax
    public struct GhostInput<TInput> where TInput : unmanaged, IInputComponentData
    Type Parameters
    Name Description
    TInput

    Your IInputComponentData struct.

    Remarks

    Never build on top of GetForCurrentTick() when capturing: InputEvent counters would be counted twice and one frame inputs would stick. For values that must sum over several frames, keep a field on your GhostBehaviour. A GhostComponentRef<TComponentType> on the same input type gives raw access to the same ECS component.

    Methods

    Capture(in TInput)

    Hands over the input for this frame. Only call this from PredictionGatherInput(PredictionGatherInputContext).

    Declaration
    public void Capture(in TInput input)
    Parameters
    Type Name Description
    TInput input

    The input filled from PrepareToCapture().

    GetForCurrentTick()

    The input for the tick being simulated. Read it from PredictionUpdate(PredictionUpdateContext). During PredictionGatherInput(PredictionGatherInputContext) this holds a previous capture, don't capture on top of it.

    Declaration
    public TInput GetForCurrentTick()
    Returns
    Type Description
    TInput

    A copy of the input component.

    PrepareToCapture()

    A fresh input to fill for this frame. Always start capturing from this, not from GetForCurrentTick().

    Declaration
    public TInput PrepareToCapture()
    Returns
    Type Description
    TInput

    A default TInput.

    TryGetCapturedAtPreviousTick(out TInput)

    Retrieve the input captured for the tick before the one being simulated. Can be used inside the prediction loop, to calculate deltas or detect changes (i.e triggers up/down).

    Declaration
    public bool TryGetCapturedAtPreviousTick(out TInput input)
    Parameters
    Type Name Description
    TInput input

    The value of the input at that tick or default if the input data is not present.

    Returns
    Type Description
    bool

    True if a input for the previous tick is present. False, otherwise.

    TryGetCapturedAtTick(in NetworkTick, out TInput)

    Retrieve the input captured for the given NetworkTick.

    Declaration
    public bool TryGetCapturedAtTick(in NetworkTick tick, out TInput input)
    Parameters
    Type Name Description
    NetworkTick tick

    The tick to retrieve the input for.

    TInput input

    The value of the input at that tick or default if the input data is not present.

    Returns
    Type Description
    bool

    False if the buffer is empty or the tick is invalid. Otherwise returns the input for the requested tick, or the closest one before it.

    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)