Hi, I'm seeing an error when I run the following codes

m_spineAnim.skeletonDataAsset = data.SkeletonData;
m_spineAnim.Initialize(true);

and the errors I'm seeing are as follows:

IndexOutOfRangeException: Index was outside the bounds of the array.
Spine.TranslateTimeline.Apply (Spine.Skeleton skeleton, System.Single lastTime, System.Single time, Spine.ExposedList`1[T] firedEvents, System.Single alpha, Spine.MixBlend blend, Spine.MixDirection direction) (at ./Library/PackageCache/com.esotericsoftware.spine.spine-csharp@4fb96bb24f/Animation.cs:531)
Spine.AnimationState.Apply (Spine.Skeleton skeleton) (at ./Library/PackageCache/com.esotericsoftware.spine.spine-csharp@4fb96bb24f/AnimationState.cs:266)
Spine.Unity.SkeletonAnimation.ApplyAnimation () (at ./Library/PackageCache/com.esotericsoftware.spine.spine-unity@4fb96bb24f/Runtime/spine-unity/Components/SkeletonAnimation.cs:252)
Spine.Unity.SkeletonAnimation.Update (System.Single deltaTime) (at ./Library/PackageCache/com.esotericsoftware.spine.spine-unity@4fb96bb24f/Runtime/spine-unity/Components/SkeletonAnimation.cs:239)
Spine.Unity.SkeletonAnimation.LateUpdate () (at ./Library/PackageCache/com.esotericsoftware.spine.spine-unity@4fb96bb24f/Runtime/spine-unity/Components/SkeletonAnimation.cs:280)
Spine.Unity.SkeletonRenderer.Initialize (System.Boolean overwrite, System.Boolean quiet) (at ./Library/PackageCache/com.esotericsoftware.spine.spine-unity@4fb96bb24f/Runtime/spine-unity/Components/SkeletonRenderer.cs:427)
Spine.Unity.SkeletonAnimation.Initialize (System.Boolean overwrite, System.Boolean quiet) (at ./Library/PackageCache/com.esotericsoftware.spine.spine-unity@4fb96bb24f/Runtime/spine-unity/Components/SkeletonAnimation.cs:187)

Using the following spine packages:
spine-csharp runtime 4.1.2
spine-unity runtime 4.1.37

Related Discussions
...

The error you're encountering when changing the skeletonDataAsset and calling Initialize(true) on your SkeletonAnimation component seems to be related to an issue with the animation timelines not matching up with the new skeleton data. This can happen if the new SkeletonDataAsset has a different structure or animations that do not align with the currently set animations or expectations of the component.

To resolve this issue, ensure that before you change the SkeletonDataAsset and reinitialize, you also set the initialSkinName to a skin that exists in the new SkeletonDataAsset and clear or set the AnimationName to an animation that exists in the new asset. This is crucial because if the component tries to apply an animation that doesn't exist in the new skeleton data, it can lead to errors like the one you're experiencing.

Here's an adjusted approach:

// Ensure the animation name exists in the new SkeletonDataAsset
m_spineAnim.AnimationName = "newAnimationName"; // Set to a valid animation name
// Optionally, set the initial skin name if needed
m_spineAnim.initialSkinName = "newSkinName"; // Set to a valid skin name or leave blank for default
// Now change the SkeletonDataAsset
m_spineAnim.skeletonDataAsset = data.SkeletonData;
// Reinitialize
m_spineAnim.Initialize(true);

Make sure that "newAnimationName" and "newSkinName" are valid names that exist in the SkeletonDataAsset you're switching to. This should help avoid the IndexOutOfRangeException by ensuring that the component is not trying to access data that doesn't exist in the new skeleton data.

    @birdkingz Sorry to hear Spinebots answer didn't help. Normally changing initialSkinName and AnimationName would be the required steps.

    Could you please share the code you are using now to change the SkeletonDataAsset? Are you sure the newly set AnimationName exists in your assigned SkeletonData data.SkeletonData?

      Harald

      Here's the codes:

      m_spineAnim.AnimationName = "idle";
      m_spineAnim.initialSkinName = "original";
      m_spineAnim.skeletonDataAsset = data.SkeletonData;
      m_spineAnim.Initialize(true);

      And yeah I have made sure the newly assigned SkeletonData has a skin name call "original" and an animation name call "idle". In fact, the m_spineAnim.skeletonDataAsset also has a skil name call "original" and an animation name call "idle"

      Also not sure is this information helpful or not but both of my skeletonDataAsset has an animation name call "atk" and it has duration of 0s. Is this something that maybe causing issue during the initialization step?

      PS: I've also made sure that dataand data.SkeletonData are not NULL

        Unfortunately I can see nothing obviously wrong with your setup. Could you please send us a minimal Unity project which still shows this issue? You can send it as a zip package to contact@esotericsoftware.com, briefly mentioning this forum thread so that we know the context. Then we can have a look at what's going wrong.

        birdkingz Also not sure is this information helpful or not but both of my skeletonDataAsset has an animation name call "atk" and it has duration of 0s. Is this something that maybe causing issue during the initialization step?

        That should be no problem.

          Glad to hear, thanks for confirming!