Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question NetworkTime.SimulationStepBatchSize

Discussion in 'NetCode for ECS' started by FaithlessOne, Sep 3, 2023.

  1. FaithlessOne

    FaithlessOne

    Joined:
    Jun 19, 2017
    Posts:
    257
    I have a question regarding the SimulationStepBatchSize:
    According to the docs this is used to reduce CPU costs. My questions are:
    1. Is there a way to disable this CPU optimization?
    2. On a ServerWorld when SimulationStepBatchSize is greater than 1, the ServerTick not gets adjusted on consecutive executions. So for example the SimulationStepBatchSize is 4 and the OnUpdate of an ECS system running inside the PredictedFixedStepSimulationSystemGroup is called 4 times with ServerTickIndex 377. I would have expected at least some additional value which indicates which tick index the loop is exactly in, but this does not seem to be the case. Are we supposed to track the exact ServerTickIndex ourselves or is there something I miss here?
     
  2. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    224
    Hey Faithless,
    Yeah, you can manually create a ClientServerTickRate struct on the server, with this variable set to 1.

    In your example: If the server was to batch 4 ServerTicks into 1 ServerTick (due to it running too slowly), NetworkTime.SimulationStepBatchSize will equal 4. Thus, you can query NetworkTime in your systems to account for this delta. I believe the TimeData.DeltaTime is also correctly scaled.
     
    FaithlessOne likes this.
  3. FaithlessOne

    FaithlessOne

    Joined:
    Jun 19, 2017
    Posts:
    257
    Thanks, Niki. Yes, especially the SystemAPI.Time.ElapsedTime and DeltaTime seems to be scaled correctly when batching with SimulationStepBatchSize happens, only the ServerTickIndex remains the same. In my project I use mostly the ServerTickIndex rather than SystemAPI.Time, so I understand that the exact ServerTickIndex has to be tracked by myself then.
     
    NikiWalker likes this.