ServerTickIndex skipped or processed twice using Pause and Frame Stepping toegether with Batching

I found a behaviour regarding the ServerTickIndex handling which seems like a bug to me in Netcode for Entities which I want to report here. It happens when stepping frame by frame with the Unity Editor in a ServerWorld. This is the setup:

  • ServerWorld with no clients connected
  • Entered PlayMode in Unity Editor and paused the game, progressing the game only with the Step-Button right besides the Pause-Button
  • ClientServerTickRate.MaxSimulationStepBatchSize has to be 2 or greater
  • ClientServerTickRate.MaxSimulationStepsPerFrame is 1
  • ClientServerTickRate.NetworkTickRate and SimulationTickRate is 60
  • ClientServerTickRate.TargetFrameRateMode is Auto

What I experience is that some ServerTickIndices get skipped while some ServerTickIndices gets processed twice. So it look like this:

  • Correctly processing ServerTickIndex 749 with a SimulationStepBatchSize of 1
  • In the next frame ServerTickIndex 751 is stated with a SimulationStepBatchSize of 2. The PredictionLoop gets executed two times in this frame one-time having ServerTickIndex 751 and one-time with 752. Outside of the PredictionLoop NetworkTime states the 751 and BatchSize of 2 and is executed one time.
  • In the next frame ServerTickIndex 752 with SimulationStepBatchSize of 1 is reported. The PredcitonLoop runs one-time with stated ServerTickIndex and also outside of the loop the NetworkTime is supplied and executed one time.

So the stated ServerTickIndices are the following in this small example: 749, 751, 752, 752. While ServerTickIndex 750 is fully missing in the execution, ServerTickIndex 752 is processed two times. This behevior seems fully wrong and leads to issues for ServerTickIndex based logic. In my project some logic may be repreatedly executed, because based on certain ServerTickIndices.

I also attached a few screenshots to show the NetworkTime flow in the debugger. All Systems in the screenshots are part of the SimulationSystemGroup, one inside and one outside of the PredictionLoop. I had to merge some screenshots cause of forum restrictions. 01_02 showing ServerTickIndex 749. In 03, 04 and 05 the situation with the batch of 751 and 752 is shown. And 06_07 shows the double execution of ServerTickIndex 752.

The issue is reproducable with Unity 2022.3.19 and Netcode 1.0.17 as well as Unity 2022.3.26 with Netcode 1.2.0. The bug does NOT occur when progressing the game normally in the Game view without pausing and stepping. It also does NOT occur when MaxSimulationStepBatchSize is 1. But the latter is not an option for me, because I use an increased Time.timeScale for debugging purpose (fast-forwarding the game) and this works best with a higher MaxSimulationStepBatchSize which I configured to 16 in my project.





Okay, I think I missunderstood something here. But just to be sure, I ask about it: When the NetworkTime.SimulationStepBatchSize is greater than 1, the other processed ticks are the ticks before the NetworkTime.ServerTick.ServerTickIndexForValidTick, right? So for example having

  • NetworkTime.SimulationStepBatchSize = 4

  • NetworkTime.ServerTick.ServerTickIndexForValidTick = 67

Then the processed ticks for this batch are these one:

  • 64
  • 65
  • 66
  • 67

In this case all things makes sense again, and there would be no bug with Frame by Frame Stepping. At least it would be useful to have this stated in the documentation. But I may have missed that.

Yes you’re right.
For reference, this logic is in NetcodeServerRateManager.ShouldGroupUpdate

var currentServerTick = networkTime.ServerTick;
currentServerTick.Increment();
var nextTick = currentServerTick;
nextTick.Add((uint)(m_UpdateCount.Length - 1));
networkTime.ServerTick = nextTick;

NetworkTime.ServerTick represents “the current tick being processed”. So it makes sense when batching to say “we’re now processing tick 67, which happens to include a delta time spanning 4 ticks instead of 1”. So you’re still at tick 67, but just with a bigger dt.

Is your issue of duplicated ticks server side still happening?

2 Likes

Thanks for your answer and your clarification. I changed the handling accordingly in my project so batches of ticks can be processed. Each tick in a batch can now be determined and handled appropriatly using the NetworkTime. This allows execution at 16 times the speed in my project, which is quite impressive. I also tested frame by frame stepping in the editor again and all server tick indices get correctly sequentially stated on the server. All works fine now!