• Runtimes
  • Basic animation changing in Unity, please help

Hey guys,
I have spent hours now trying to understand how to change the currently playing animation of a spine animation during runtime in Unity.

I have looked at the runtime documentation, but cannot figure it out because they create everything from ground zero in Java. In unity I already have my skeleton and animation all set up to run when the game starts. Can someone PLEAAASE share some basic code of how they access the spine skeleton object that is attached to an object and how you would change the animation?

I am using the 2dtoolkit if that changes anything. Currently at a GameJam trying to figure this out, so any input is appreciated.

Related Discussions
...

SkeletonAnimation initializes with a Spine.AnimationState member held by its field called "state".

Access it by using GetComponent<SkeletonAnimation>() or something and then getting the .state field.
Use state.SetAnimation or state.AddAnimation to change the animations.

This code-friendly way of manipulating animations only works if you choose <No Change> as the SkeletonAnimation's initial/default animation IN THE INSPECTOR. DON'T FORGET TO DO THIS.

I'm speaking in terms of Spine-Unity but assigning animations should work pretty much the same way in Spine-TK2D

Thank you for the response. For whatever reason I can't get it to work by doing "state.SetAnimation". Instead when I say: skeleton.animationName = "run" then it will play the animation. I set the inspector to No Change as you suggested. Maybe I just don't understand how to use "SetAnimation", do you have to tell it to play after setting it?

Also any idea on how to "mix" when changing from one animation to another?

See the bolded text above.