• Unity
  • CPU Optimization

Hello,

We use Spine 3.6.41 and last unity-spine plugin.
We currently have a cpu problem is our project. The Update() of Spine is really expensive. On PC , each player cost 0.2 ms (up to 4 players). On consoles (XboxOne - Switch) it's more 0.8 ms per player....

Players have between 50-70 bones, 500-1500 vertex transform in binary export mode, and we use "cleanup" command in spine editor.
It would be difficult to reduce bone/mesh count without reducing quality.

I tried to call the Update of SkeletonAnimator only in 30 fps, but the result is that the cpu spike is here only every two frame instead of every frame...

Do you have suggestions to reduce cpu cost (We have already read the Metrics view doc page)?

Related Discussions
...

If updating skeletons at 30 fps is feasible, update half of them every other 60 fps frame. This will cut your update time by half.

Is the time taken in Skeleton updateWorldTransform or AnimationState apply?

For updateWorldTransform, do you need to update all the bones? If you have some bones that exist only for certain effects, you could special case those bones to skip updating them when they aren't needed. Also, some spine-unity features make cause multiple updateWorldTransform calls per frame. You could try to avoid these features.

For apply, you could try to reduce the number of timelines (rows in the dopesheet) for your animations. If you have timelines with just a few keys, removing the timelines entirely reduces the amount of processing that needs to be done.

Other ways to reduce time applying animations can be to reduce the number of Bezier curve keys. For an extreme measurement of how much you can save, change all keys to linear and see how performance changes.

You could check if a linear search to find the current key is faster for you (note this has nothing to do with linear vs Bezier keys), relevant code is here:
spine-runtimes/Animation.cs at 3.6
Here is a linear search implementation (in Java):
spine-runtimes/Animation.java at 3.6

What timeline type is taking the most time?

How many animations are you applying at the same time? Note even when using a single track, if using a mix duration between animations, 2 will be applied at the same time for the mix duration.

SkeletonAnimator in particular wasn't optimized for speed. (though a few optimizations have been added over time)
It's a workaround for users who want to use Mecanim instead of making their own animation management code.
Mecanim itself doesn't expose enough to make seamless integration with Spine so SkeletonAnimator spends some amount extra processing to compensate.

If you are using a frame-skipping update pattern, make sure you stagger the updates instead of calling them all on the same frame or you will get the cpu spike every other frame as you described.
call 50% of your skeletons update on frame 1, then the other 50% on frame 2, then back to the first set on frame 3, etc...

The advice above about minimizing timelines and timeline types still apply.

Hello,

The time is taken by AnimationState apply (mostly).
Changing curves from bezier to linear didn't reduce the cost (or not enough to see it in profiler).
I tried using LinearSearch instead of BinarySearch but it did not help.
There is only one anim at same time (with sometime some blend), so maybe 2 anims at the same time.
Finally the 30 fps animations is not acceptable for us, so will find another way...

Is there a particular timeline type that takes the most time?

Here is a screenshot of the profiler (deep) for a player :