docs.unity3d.com
    Show / Hide Table of Contents

    Class NetworkTimeSystem

    NetworkTimeSystem is a standalone system which can be used to run a network time simulation. The network time system maintains both a local and a server time. The local time is based on

    Inheritance
    Object
    NetworkTimeSystem
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.Netcode
    Syntax
    public class NetworkTimeSystem

    Constructors

    NetworkTimeSystem(Double, Double, Double, Double)

    The constructor class for NetworkTickSystem

    Declaration
    public NetworkTimeSystem(double localBufferSec, double serverBufferSec, double hardResetThresholdSec, double adjustmentRatio = 0.01)
    Parameters
    Type Name Description
    Double localBufferSec

    The amount of time, in seconds, the server should buffer incoming client messages.

    Double serverBufferSec

    The amount of the time in seconds the client should buffer incoming messages from the server.

    Double hardResetThresholdSec

    The threshold, in seconds, used to force a hard catchup of network time.

    Double adjustmentRatio

    The ratio at which the NetworkTimeSystem speeds up or slows down time.

    Properties

    AdjustmentRatio

    Gets or sets the ratio at which the NetworkTimeSystem speeds up or slows down time.

    Declaration
    public double AdjustmentRatio { get; set; }
    Property Value
    Type Description
    Double

    HardResetThresholdSec

    Gets or sets a threshold in seconds used to force a hard catchup of network time.

    Declaration
    public double HardResetThresholdSec { get; set; }
    Property Value
    Type Description
    Double

    LocalBufferSec

    Gets or sets the amount of time in seconds the server should buffer incoming client messages. This increases the difference between local and server time so that messages arrive earlier on the server.

    Declaration
    public double LocalBufferSec { get; set; }
    Property Value
    Type Description
    Double

    LocalTime

    The current local time with the local time offset applied

    Declaration
    public double LocalTime { get; }
    Property Value
    Type Description
    Double

    ServerBufferSec

    Gets or sets the amount of the time in seconds the client should buffer incoming messages from the server. This increases server time. A higher value increases latency but makes the game look more smooth in bad networking conditions. This value must be higher than the tick length client side.

    Declaration
    public double ServerBufferSec { get; set; }
    Property Value
    Type Description
    Double

    ServerTime

    The current server time with the server time offset applied

    Declaration
    public double ServerTime { get; }
    Property Value
    Type Description
    Double

    Methods

    Advance(Double)

    Advances the time system by a certain amount of time. Should be called once per frame with Time.unscaledDeltaTime or similar.

    Declaration
    public bool Advance(double deltaTimeSec)
    Parameters
    Type Name Description
    Double deltaTimeSec

    The amount of time to advance. The delta time which passed since Advance was last called.

    Returns
    Type Description
    Boolean

    Reset(Double, Double)

    Resets the time system to a time based on the given network parameters.

    Declaration
    public void Reset(double serverTimeSec, double rttSec)
    Parameters
    Type Name Description
    Double serverTimeSec

    The most recent server time value received in seconds.

    Double rttSec

    The current RTT in seconds. Can be an averaged or a raw value.

    ServerTimeSystem()

    Creates a new instance of the NetworkTimeSystem class for a server instance. The server will not apply any buffer values which ensures that local time equals server time.

    Declaration
    public static NetworkTimeSystem ServerTimeSystem()
    Returns
    Type Description
    NetworkTimeSystem

    The instance.

    Sync(Double, Double)

    Synchronizes the time system with up-to-date network statistics but does not change any time values or advance the time.

    Declaration
    public void Sync(double serverTimeSec, double rttSec)
    Parameters
    Type Name Description
    Double serverTimeSec

    The most recent server time value received in seconds.

    Double rttSec

    The current RTT in seconds. Can be an averaged or a raw value.


    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Constructors
      • NetworkTimeSystem(Double, Double, Double, Double)
    • Properties
      • AdjustmentRatio
      • HardResetThresholdSec
      • LocalBufferSec
      • LocalTime
      • ServerBufferSec
      • ServerTime
    • Methods
      • Advance(Double)
      • Reset(Double, Double)
      • ServerTimeSystem()
      • Sync(Double, Double)
    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on 26 October 2023