• Unity
  • Changing refresh rate at runtime to mimic No Interpolation

  • Змінено
Related Discussions
...

I've been hitting my head against a wall trying to solve this, and while the answer has come up a number of times in other threads that this needs to be done, there's never any details as to HOW it should be done, so I'm basically stuck.

I want to limit the refresh rate so that the spine animation only draws every 1/30th a frame for a 30fps animation. Basically I want the animation to play in Unity the way it plays in Spine when interpolation is turned off (only displaying whole frames rather than every in-between). I understand based on prior answers from Pharan and Nate that this is the correct way to go about this (editing the runtime scripts that control the animation updates) but have absolutely no idea where to start with actually implementing this. On top of that most of the posts I could find about this were a couple years old, so there may already be some kind of built in implementation as well. So I figured it couldn't hurt to ask.

In any case any help on this would be greatly appreciated! Thanks 😃

The AnimationState is advanced by passing it a delta time, here:
spine-runtimes/SkeletonAnimation.cs at 3.6

The delta time is the time since the last frame. What you want to do is only pass a delta time that is at least 1/30th of a second. Something like:

private float accumulate;
public void Update (float deltaTime) {
   ...
   accumulate += deltaTime;
   float fps = 1 / 30f;
   float step = accumulate - (accumulate % fps);
   accumulate -= step;
   step *= timeScale;
   skeleton.Update(step);
   state.Update(step);
   state.Apply(skeleton);
   ...
}

The accumulate field stores the amount of time from previous frames that did not fit evenly into 1/30th of a second.

  • Versy відповіли на це.

    Awesome, thanks Nate!

    I could've sworn we had this as an example script before. I'll make sure an example of it gets added in the 3.7 runtime.

    рік пізніше
    Pharan написав

    I could've sworn we had this as an example script before. I'll make sure an example of it gets added in the 3.7 runtime.

    Is there an example for this in 3.8 runtimes?

    EDIT: Found it.

    5 років пізніше

    Nate
    Sorry to bump this old thread, but is there an Unreal version of this code somewhere?