SoulKarl

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 :D
SoulKarl
Posts: 15

Nate

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.
User avatar
Nate

Nate
Posts: 8365

SoulKarl

Awesome, thanks Nate!
SoulKarl
Posts: 15

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.
User avatar
Pharan

Pharan
Posts: 5281


Return to Unity