docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct NetworkTime

    Present on both client and server world, singleton component that contains all the timing characterist of the client/server simulation loop.

    Implements
    IComponentData
    IQueryTypeParameter
    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 NetworkTime : IComponentData, IQueryTypeParameter

    Fields

    EffectiveInputLatencyTicks

    The current effective ForcedInputLatencyTicks value (in ticks). Client-only!

    Declaration
    public uint EffectiveInputLatencyTicks
    Field Value
    Type Description
    uint
    Remarks

    Note: This value will increase if/when the clients ping value is greater than MaxPredictAheadTimeMS.

    InterpolationTick

    The current interpolated tick (integral part). Always less than the ServerTick on the Client (and equal to ServerTick on the server).

    Declaration
    public NetworkTick InterpolationTick
    Field Value
    Type Description
    NetworkTick

    InterpolationTickFraction

    The fractional part of the tick (XXX.fraction). Always in between (0.0, 1.0]

    Declaration
    public float InterpolationTickFraction
    Field Value
    Type Description
    float

    ServerTick

    The current simulated server tick the server will run this frame. Always start from 1. 0 is considered an invalid value. The ServerTick value behaves differently on client vs the server. On the server:

    • it is always a "full" tick
    • i.e. it is strict and monotone, and only increments on the server DGS render (i.e. UnityEngine) frame rate (which you can configure to be the same as this).
    • is therefore the same inside or outside the prediction loop On the client:
    • it is the tick the client is currently predicting the server should simulate on this frame. I.e. Depends on current EstimatedRTT and TargetCommandSlack values.
    • can be either a full or partial (see details on client partial ticks in docs).
    • it is not monotone:
      • in some rare/recovery situations, it may rollback, or jump forward (due to time/lag adjustments).
      • during the prediction loop, the ServerTick value is changed to match either the last full simulated tick or, in case of a rollback (because a snapshot has been received), to the oldest received tick among all entities.
    • in both cases, this value will be reset to current predicted server tick at the end of the prediction loop.
    Declaration
    public NetworkTick ServerTick
    Field Value
    Type Description
    NetworkTick
    Remarks

    Use InputTargetTick (not ServerTick!) when assigning a tick value to your command data values for AddCommandData<T>(DynamicBuffer<T>, T).

    ServerTickFraction

    Only meaningful on the client that run at variable step rate. On the server is always 1.0. Always in range is (0.0 and 1.0].

    Declaration
    public float ServerTickFraction
    Field Value
    Type Description
    float

    SimulationStepBatchSize

    The number of simulation steps this tick is scaled with. This is used to make one update which covers N ticks in order to reduce CPU cost. This is always 1 for partial ticks in the prediction loop, but can be more than 1 for partial ticks outside the prediction loop.

    Declaration
    public int SimulationStepBatchSize
    Field Value
    Type Description
    int

    Properties

    InputTargetTick

    The tick we should be gathering (i.e. raising, sending) input commands for, for them to arrive in time to be processed by the server. It is identical to the ServerTick except; a) when using MaxPredictAheadTimeMS with a very high ping connection, and b) when using ForcedInputLatencyTicks. The four timelines are therefore in this order: Interpolation Tick (oldest) -> Snapshot Arrival Tick (from the server) -> ServerTick (client prediction) -> InputTargetTick (i.e. inputs being sent).

    Declaration
    public NetworkTick InputTargetTick { get; }
    Property Value
    Type Description
    NetworkTick
    Remarks

    Use this variable (not ServerTick) when assigning a tick value to your command data values for AddCommandData<T>(DynamicBuffer<T>, T).

    IsCatchUpTick

    Only valid on server. When the server determines that it is behind by more than one tick, it queries MaxSimulationStepBatchSize and MaxSimulationStepsPerFrame to determine how to catch up. If your configuration causes the server to simulate two or more ticks within a single frame, all non-final ticks will have the catchup flag set to true.
    Note: Batching multiple ticks into one tick will not - by itself - be considered a catch up tick.

    Declaration
    public bool IsCatchUpTick { get; }
    Property Value
    Type Description
    bool
    Remarks

    This flag is used to limit the sending of snapshots (via GhostSendSystem) when SendSnapshotsForCatchUpTicks is false.

    IsFinalFullPredictionTick

    Only valid inside the prediction loop. The current server tick which will be the last full tick we are predicting

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

    IsFinalPredictionTick

    Only valid inside the prediction loop. The current server tick which will be the last tick to predict

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

    IsFirstPredictionTick

    Only valid inside the prediction loop. The server tick the prediction is starting from.

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

    IsFirstTimeFullyPredictingTick

    Only valid inside the prediction loop. True when this ServerTick is being predicted in full for the first time. "In full" meaning the first non-partial simulation tick. I.e. Partial ticks don't count.

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

    IsInPredictionLoop

    Indicate that the current ServerTick is a predicted one and the simulation is running inside the prediction group.

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

    IsPartialTick

    True if the current tick is running with delta time that is a fraction of the ServerTickDeltaTime. Only true on the client when running at variable frame rate.

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

    NumPredictedTicksExpected

    Counts the number of predicted ticks expected to trigger on this frame, ignoring batching. Written at the start of the prediction loop. Thus, client only, and is set BEFORE the first tick occurs.

    Declaration
    public readonly int NumPredictedTicksExpected { get; }
    Property Value
    Type Description
    int

    PredictedTickIndex

    Counts the number of predicted ticks that have been triggered on this frame (while inside the prediction loop). Thus, client only, and increments BEFORE the tick occurs (i.e. the first predicted tick will have a value of 1). Outside the prediction loop, records the current or last frames prediction tick count (until prediction restarts).

    Declaration
    public readonly int PredictedTickIndex { get; }
    Property Value
    Type Description
    int

    Methods

    ToFixedString()

    Helper to debug NetworkTime issues via logs.

    Declaration
    public FixedString512Bytes ToFixedString()
    Returns
    Type Description
    FixedString512Bytes

    Formatted string containing NetworkTime data.

    Implements

    IComponentData
    IQueryTypeParameter
    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)