• RuntimesUnity
  • How to start animation with runtime instance ?

I tried the code below. The model is visible, but the animation has not started. How do I start the animation?

SkeletonGraphic skeletonGraphic = SkeletonGraphic.NewSkeletonGraphicGameObject(_skeletonDataAsset, transform, _defaultMaterial);
skeletonGraphic.startingAnimation = "Idle";
skeletonGraphic.startingLoop = true;
    Related Discussions
    ...

    khc In general, the startingAnimation property of the SkeletonGraphic component should not be used to set an animation from code. Use AnimationState API to set an animation to your skeleton.

    The following is a simple example script that sets the Idle animation with loop:true to track 0 of the AnimationState of the SkeletonGraphic component of the GameObject to which this script is attached:

    using Spine.Unity;
    using System.Collections;
    using UnityEngine;
    
    public class SetAnimationToSkeletonGraphic : MonoBehaviour
    {
        SkeletonGraphic skeletonGraphic;
    
        void Start()
        {
            skeletonGraphic = GetComponent<SkeletonGraphic>();
            skeletonGraphic.AnimationState.SetAnimation(0, "Idle", true);
        }
    }

    See the API Reference for more information on the SetAnimation() method of AnimationState.

    Great !!
    Thank you for the help, I got it to work.