Why animation group master frame doesn't change for 1 step after starting it when lockstep is active?

Hi. I’m having a problem understanding why this is happening. I don’t know if it is a bug or not. I know it’s not a big deal but I’m currently implementing a rollback networking model for a fighting game and in this model, every frame (step) counts. this is an example PG.
if you open the console you can see that the master frame of the currently playing animation group which is “Samba” doesn’t change after step 0. Is there a workaround for this so that after step 0 the master frame changes to 1?

onBeforeStepObservable is run right at the start of a step, before the animations have been processed. You should use onAfterAnimationsObservable if you want to add code that runs after animations have been processed:

@Evgeni_Popov if you check the PG you can see that there are 2 logs on each step. one onBeforeStep and one onAfterStep and the onAfterStep observers get notified even after onAnimationsEnd observers.

here is a screenshot and as you can see the master frame of the animation group after step 0 is still 0. I also test this on different steps. when you stop an AnimationGroup and then start it in onBeforeStep on another step, the master frame doesn’t change for 1 step

You should not delete and recreate the engine inside the scene, as the Playground is still using the engine it created and not the new one. You should provide a createEngine function instead:

With this change, the animation plays at the right speed and I get:


There are a few 0 at the start because the animation code returns early if there are still some pending operations in the scene, like loading of textures. You can get rid of them if you wait for the scene to be ready:

With this change, I get:


Which is the expected output:

  • the first time the animation code runs, the delta time is 0 (because some internal lastTime variable is set to the current time, meaning currentTime-lastTime==0) so you get masterFrame = 0 in onAfterStep
  • the second time, delta time is > 0, but you get 0 in onBeforeStep because this observable is triggered before the animation code runs. However, onAfterStep is called after the animation code, so you get the right value for masterFrame

Does this make sense?

@Evgeni_Popov Yeah, that makes sense. now I want to know is there a workaround for this? because as I said I’m implementing a rollback networking model for a fighting game and this would cause a desync problem. Would it be possible to provide a solution so that when I start the “AnimationGroup” in the “onBeforeStep” observer, the main frame of the “AnimationGroup” would increase in the “onAfterStep” observer of the same step?

What you can try to do is to set the Animatable._localDelayOffset property to 0 after you started the animation group (lines 69-71):