• RuntimesUnity
  • Disable/Enable SkeletonAnimation.Update for Infrequent Animations

Hello, I have SkeletonAnimation objects in my game which play very infrequently -
for example a storage chest that stands still until it is opened & closed, and then sits still
until the player interacts with it again. It seems wasteful to be updating in the time between.
I am hoping to reduce unnecessary Update calls, as Spine objects already eat up much of my frame budget.

So the question is:

Is there a recommended method for disabling the SkeletonAnimation.Update when it is not used? Said another way, is there a recommended way to manually Play one-off animations, and then stop updating?

I tried disabling the SkeletonAnimation component after a callback from the skeletonAnimation.AnimationState.Complete event, but disabling the component makes the mesh disappear.

I have seen other posts related to this, but they are either 10 years old or not the same question. Thank you in advance!

  • Harald ha risposto a questo messaggio
    Related Discussions
    ...

    @nd_nomad Disabling SkeletonAnimation is the standard way for this. At SkeletonGraphic there is an additional freeze parameter available which can be used instead, but this does not apply for SkeletonAnimation or any SkeletonRenderer subclass.

    nd_nomad I tried disabling the SkeletonAnimation component after a callback from the skeletonAnimation.AnimationState.Complete event, but disabling the component makes the mesh disappear.

    Then something is wrong with your code which disables the component. The following code simply disables updates and keeps the last frame static and visible:

    using Spine;
    using Spine.Unity;
    using UnityEngine;
    
    public class TestDisableSkeletonAnimation : MonoBehaviour
    {
        public SkeletonAnimation skeletonAnimation;
        void Start()
        {
            skeletonAnimation = this.GetComponent<SkeletonAnimation>();
            skeletonAnimation.AnimationState.Complete += DisableSkeletonAnimation;
        }
    
    	private void DisableSkeletonAnimation (TrackEntry trackEntry) {
            skeletonAnimation.enabled = false;
        }
    }

    You can also check out the Spine Examples/Other Examples/FixedTimestepUpdates example scene that comes with the spine-unity runtime on how to manually issue updates in different intervals. These also disable the SkeletonAnimation component and call skeletonAnimation.Update() manually to update e.g. only every 2nd frame.