• Unity
  • How can I check what animation is playing each track?

Related Discussions
...

Hello,

I am trying to mix multiple animations with Unity, and I often wonder what animation is playing each track now.
Then I wrote the following code:

using UnityEngine;
using System.Collections;
using Spine.Unity;

public class CheckingTrack : MonoBehaviour
{
    void Update()
    {
        var skeletonAnimation = GetComponent<SkeletonAnimation>();
        var currentTrackEntry0 = skeletonAnimation.state.GetCurrent(0).Animation;
        var currentTrackEntry1 = skeletonAnimation.state.GetCurrent(1).Animation;
        var currentTrackEntry2 = skeletonAnimation.state.GetCurrent(2).Animation;
        var currentTrackEntry3 = skeletonAnimation.state.GetCurrent(3).Animation;
        Debug.Log ("Track0:" + currentTrackEntry0 + " Track1: " + currentTrackEntry1 + " Track2: " + currentTrackEntry2 + " Track3: " + currentTrackEntry3); 
    }
}

Well, this is working, but if possible, I'd like to see the result on game view.
I thought I can override the currentTrackEntry to textUI, but the type is difference.

Could you give me some advice?
Thank you in advance.

I'm afraid I don't understand the following sentence:

misaki_m wrote

I thought I can override the currentTrackEntry to textUI, but the type is difference.

Could you please describe in more detail what you have tried and what did not work?
Basically you should be able to simply assign the name of the currentTrackEntry.Name to any textField.text property.

Thank you for your reply!
You are right, the ".Name" is just I missed.

For other users information, I write down my bad code example.
I tried like the following:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Spine.Unity;

public class CheckingTrack : MonoBehaviour
{
    public Text AnimationNameField;

void Update()
{
    var skeletonAnimation = GetComponent<SkeletonAnimation>();
    var currentTrackEntry = skeletonAnimation.state.GetCurrent(0).Animation;

    AnimationNameField.text = (currentTrackEntry);
 }
}

Then, I got this error message:

Assets/CheckingTrack.cs(21,36): error CS0029: Cannot implicitly convert type 'Spine.Animation' to 'string'

What I should fix is this line:

AnimationNameField.text = (currentTrackEntry);

It should be like this:

AnimationNameField.text = (currentTrackEntry.Name);

It is working now, thank you so much!

Nice. I wanted to do this for some time, so I thank you for bringing it up.

But I'm also wondering if there is a way to do this without specifying the track numbers.

Something like getting an array of entries which are playing any (not set to empty) animations at the moment?

@misaki_m Glad to hear you've figured it out, thanks for letting us know!

Abelius wrote

But I'm also wondering if there is a way to do this without specifying the track numbers.
Something like getting an array of entries which are playing any (not set to empty) animations at the moment?

@[deleted]
If only we had some documentation pages where such things could be looked up. Oh, wait a second..
AnimationState tracks
:nerd:

Just use the uppercase tracks like animationState.Tracks in csharp. Then you can iterate over all tracks and continue; over those that are empty.

Harald wrote

@[deleted]
If only we had some documentation pages where such things could be looked up. Oh, wait a second..

:lol:

Point taken. And thanks!