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.