So I've run into another daft problem which other people will likely spot right away, I did check the thread that was posted in another answer to this problem.
Noteworthy Spine-Unity Topics
However when I tried this auto-reset code all that happened was that my animated sprite just went completely static, which is of course not what I want at all. The problem I have is this, I have an admittedly rough but correct code with changing my animations and within the "Skeleton Animation" script you can see the editor change the animation perfectly according to how I want however the sprite itself does not change and actually stays stuck in my idle animation, weirdly, the animation flipping works absolutely great.
The concept I'm using is really simple and I'm using code from a different tutorial before that has worked fine before however when applied to Spine's code the animations aren't correctly changing, I'll post up the update function to give you an idea of what I'm attempting.
void Update () {
// rabbitcontroller.SetBool ("Grounded", grounded);
if (Input.GetKey (KeyCode.Space) && grounded) {
GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D> ().velocity.x, jumpHeight);
}
if (Input.GetKey (KeyCode.D)) {
GetComponent<Rigidbody2D> ().velocity = new Vector2 (moveSpeed, GetComponent<Rigidbody2D> ().velocity.y);
}
if (Input.GetKey (KeyCode.A)) {
GetComponent<Rigidbody2D> ().velocity = new Vector2 (-moveSpeed, GetComponent<Rigidbody2D> ().velocity.y);
}
// rabbitcontroller.SetFloat ("Speed", Mathf.Abs (GetComponent<Rigidbody2D> ().velocity.x));
if (GetComponent<Rigidbody2D> ().velocity.x < 0) {
skeletonAnimation.skeleton.flipX = true;
spineAnimationState.SetAnimation (0, "Idle", false);
spineAnimationState.SetAnimation (0, "Run Cycle", true);
} else if (GetComponent<Rigidbody2D> ().velocity.x > 0) {
spineAnimationState.SetAnimation (0, "Idle", false);
skeletonAnimation.skeleton.flipX = false;
spineAnimationState.SetAnimation (0, "Run Cycle", true);
}
if ( GetComponent<Rigidbody2D>().velocity.x == 0 )
{
spineAnimationState.SetAnimation (0, "Run Cycle", false);
spineAnimationState.SetAnimation (0, "Idle", true);
}
As you can see, the concept is simple, if the character is moving have the player play the Run Cycle and then when the player is stopped place the thing on Idle, as I said before, the editor is showing the skeleton changing the animation but there are no changes occurring with the sprite itself.
I'm probably doing something daft like overwriting something somewhere without realising it I suspect, I'll keep reading through the documentation on the AnimationState and so on to see if I can fix it myself while I wait for a response.
22 Oct 2016, 14:11
Ohhhh! Hang on, I just realised something I need to confirm, is this because of the animation tracks perhaps? I don't know how to use those correctly.
23 Oct 2016, 11:09
OKAY!
After reading through this section of the topic: [runtimes] AnimationState improvements · Issue #621 · EsotericSoftware/spine-runtimes · GitHub
I found the problem! It was to do with animation mixing, it looks like the default settings were messing with it and I'm getting much better results now, I simply needed to go into the skeletonData and add custom animation mixing for each of my transitions to the different animations, so the animation mixing clearly acts almost like an animation controller.
23 Oct 2016, 11:41
While I have the animations changing now I've run into the problem listed in the github notes about these sorts of issues.
Result: a is left in the state it was when the animation changed, b snaps into position.
Solution: Need a TrackEntry setting for animations to mix to/from the setup pose during mixing.
Would someone mind explaining what a TrackEntry is and how this is supposed to fix the poses? I'm currently experiencing the animations only switching to the start pose and not playing when I set the mixes to a low number.
23 Oct 2016, 11:43
I seem to be just getting everything fixed by myself, sorry about that, it looks like I just needed to increase the settings, maybe I just need to keep fiddling with everything until I get the results I want.
23 Oct 2016, 11:57
After going through the documentation I'm about ready to give up, but so far I've managed to get the animations changing perfectly to their respective start poses, unfortunately I just don't know enough about spine to fix this so I'm still looking for help with this particular problem if it's not too much bother.
23 Oct 2016, 12:44
Sorry for the spam all, but I've definitely fixed everything now, the culprit was in fact.
spineAnimationState.setAnimation (0, "AnimationName", true);
The experienced guys are probably rolling their eyes at this but I had no idea 😛
The correct code to use is
skeletonAnimation.AnimationName = "AnimationName";
It looks like I was simply setting the animation to the start position every time without even realising it, which is why the animation wouldn't play as I was expecting, everything is working fantastically now.