• Runtimes
  • How do I get the animation name?

Related Discussions
...

Hi there,

How do I get the name of an Animation?

var stateData = skeletonAnimation.SkeletonDataAsset;
 var data = stateData.GetSkeletonData(false);
 var animation = data.FindAnimation("Interaction");

I can do the above to find var animation. But from "animation", how do I now go back and find the animation name? I can't do "animation.name" to access that read-only property, although according to the API, it should work.

In spine-csharp access to the private name field is provided through aName` property. So you need to do this:

string name = animation.Name;

I encourage looking at the code to see what is available, you should find it very straightforward. For example:
https://github.com/EsotericSoftware/spine-runtimes/blob/4.1-beta/spine-csharp/src/Animation.cs#L80-L81

Hi Nate,

Thanks for the reply. I think the API is excellent. The problem is that when I used that property, it's throwing an error.

'Animation' does not contain a definition for 'name' and no accessible extension method 'name' accepting a first argument of type 'Animation' could be found (are you missing a using directive or an assembly reference?)

I checked the type of object that var animation = data.FindAnimation("Interaction"); is, and it's a Spine.Animation.

So this should work, but doesn't.

EDIT: So, this is case sensitive. The problem is that in the API, it shows lowercase "name" to get the name, whereas the actual codebase references "Name." Not sure why there is that difference.

Glad to hear you've figured it out, sorry that things might be a bit confusing at first.

Please note that the Spine runtime API reference lists method and property names in the Java form of spine-libgdx, as described at the top of the page.

esotericsoftware.com/spine-api-reference a écrit

To simplify documentation, the API reference below is programming language agnostic. There may be minor differences for some languages, such as start caps for spine-csharp and class name prefixes on methods for spine-c.

Each runtime differs slightly in that e.g. spine-csharp uses properties like MyProperty instead of accessor methods getMyProperty(), to keep to language guidelines and utilize language features that help reduce unnecessary code. And in general as described above, in spine-csharp methods and properties start with a capital letter.