• RuntimesUnity
  • FPS Drop in Unity with Masked Spine Animation

I’m experiencing a significant FPS drop in Unity when using Spine animations with a mask. Normally, the FPS stays around 60, but with the mask applied, it drops to 40–30. I have tested importing the same files in Unity both with and without the mask. Without the mask, the performance is fine, but with it, the FPS drops significantly.

Since using the mask is essential for our Spine animations, is there an alternative way to export or optimize the setup to retain a stable FPS in Unity? I have exported the Spine animation in Binary format.

Any suggestions would be appreciated.

Related Discussions
...

Using masks with Spine animations in Unity can indeed lead to performance issues, as masks typically require additional rendering passes which can be costly. Here are a few suggestions to help optimize your setup and maintain a stable FPS:

  1. Binary Export: You are already using binary export, which is good as it is faster than JSON. Ensure that all your assets are optimized for performance.

  2. Shader Optimization: Consider using custom shaders that are optimized for your specific use case. You might need a shader that efficiently handles masking without excessive overhead. The Spine/Sprite/* shaders in spine-unity are compatible with SpriteMasks, but you may need to adjust them for better performance.

  3. Reduce Complexity: Simplify your animations and reduce the number of bones and vertices if possible. This can help reduce the computational load.

  4. Pooling: Use object pooling to manage your Spine animations. This can help reduce the overhead of instantiating and destroying objects during gameplay.

  5. Stencil Buffer: If you are using a stencil buffer for masking, ensure that it is implemented efficiently. Custom shaders that write to the stencil buffer can be optimized to minimize performance impact.

  6. Profile and Optimize: Use Unity's Profiler to identify bottlenecks in your rendering pipeline and optimize accordingly.

By implementing these strategies, you should be able to improve the performance of your masked Spine animations in Unity.

I assume by "mask" you mean "clipping attachment" in Spine terminology. Be sure to see here:
http://esotericsoftware.com/spine-clipping#Performance

The metrics view can help you to minimize the number of clipping polygons and clipping triangles:
https://esotericsoftware.com/spine-metrics#Clipping-polygons

Whenever possible, don't use clipping attachments, especially not for entire complex skeletons. Sometimes things can be rearranged so attachments move under other attachments, giving the appearance of clipping without any performance hit.