The OnBecameVisible/OnBecameInvisible thing is another option. The best solution depends on how your game works. Basing your skeleton/character activity on visibility works well for some games but not others, and you need to be the judge.
Performance tips on the Skeleton structure include not having too many keys, too many bones, or too many vertices on meshes on the skeletons that you use the most. For animations, try the Clean Up
button to remove unnecessary keys as extra keys can need too much calculation if you really have a lot of them * a lot of skeletons. If you have a lot of that skeleton, try to limit your use of IK and Path constraints.
You can also disable the SkeletonAnimation component and call its Update
and LateUpdate
yourself manually, skipping frames as needed.
Here's a sample component that does that:
using UnityEngine;
using Spine.Unity;
public class ManualUpdateSkeletonAnimation : MonoBehaviour {
public SkeletonAnimation skeletonAnimation;
[Range(1/60f, 1f/8f)] // slider from 60fps to 8fps
public float timeInterval = 1f / 24f; // 24fps
float deltaTime;
#if UNITY_EDITOR
void OnValidate () {
if (skeletonAnimation == null)
skeletonAnimation = GetComponent<SkeletonAnimation>();
}
#endif
void Start () {
if (skeletonAnimation == null)
skeletonAnimation = GetComponent<SkeletonAnimation>();
skeletonAnimation.Initialize(false);
skeletonAnimation.clearStateOnDisable = false;
skeletonAnimation.enabled = false;
ManualUpdate();
}
void Update () {
deltaTime += Time.deltaTime;
if (deltaTime >= timeInterval)
ManualUpdate();
}
void ManualUpdate () {
skeletonAnimation.Update(deltaTime);
skeletonAnimation.LateUpdate();
deltaTime -= timeInterval; //deltaTime = deltaTime % timeInterval; // optional time accuracy.
}
}