- Editado
SkeletonGraphic Animations in Unity
Hi! I'm a begginer coding with Spine, I just never used the internal functions of it to code my animations (always used Mecanim + Skeleton Animator).
So here's my question (in c#): How do I code in SkeletonGraphic to switch between different animations?
Example:
private SkeletonGraphic skeletonGraphic;
[SpineAnimation]
public string customAnimation;
public void SetAnimation(string animation)
{
animation = customAnimation;
// HERE I WILL CODE THAT THE "CURRENT SKELETONG GRAPHIC ANIMATION" CHANGES TO MY "CUSTOM ANIMATION"
}
This Script will be attached to the SkeletonGraphic object, that's why I add a reference to this component.
Thanks for the support!
SOLVED:
OKAY! I didnt take a look at the API.... ye, I was so lazy....
In case this could be useful for anyone, there's the quick code solution:
private SkeletonGraphic skeletonGraphic;
[SpineAnimation]
public string normalAnim;
void Start()
{
skeletonGraphic = GetComponent<SkeletonGraphic>();
}
public void SetNormal()
{
skeletonGraphic.AnimationState.SetAnimation(0, normalAnim, true);
}
:sun: :sun: :sun: :sun: :sun:
Aesop escribióHi! I'm a begginer coding with Spine, I just never used the internal functions of it to code my animations (always used Mecanim + Skeleton Animator).
So here's my question (in c#): How do I code in SkeletonGraphic to switch between different animations?
Example:
private SkeletonGraphic skeletonGraphic; [SpineAnimation] public string customAnimation; public void SetAnimation(string animation) { animation = customAnimation; // HERE I WILL CODE THAT THE "CURRENT SKELETONG GRAPHIC ANIMATION" CHANGES TO MY "CUSTOM ANIMATION" }
This Script will be attached to the SkeletonGraphic object, that's why I add a reference to this component.
Thanks for the support!
SOLVED:
OKAY! I didnt take a look at the API.... ye, I was so lazy....
In case this could be useful for anyone, there's the quick code solution:private SkeletonGraphic skeletonGraphic; [SpineAnimation] public string normalAnim; void Start() { skeletonGraphic = GetComponent<SkeletonGraphic>(); } public void SetNormal() { skeletonGraphic.AnimationState.SetAnimation(0, normalAnim, true); }
:sun: :sun: :sun: :sun: :sun:
Whew. 3 years later. But still super helpful! Thank you!~
I tried going through here:
http://en.esotericsoftware.com/spine-unity
But glad to have found your thread before I pulled out my hair. :rofl:
A neat little trick is to also create a small Enum. If you have a lot of animations you wish to cycle through.
enum Expression { Happy, Sad, Idle }
public void SetNormal()
{
_skeletonGraphic.AnimationState.SetAnimation(0, Expression.Sad.ToString(), true);
}
Then you can ensure you won't have typo errors in the inspector!
Did you look at the example scenes and scripts? Spine Examples/Getting Started/*
shows the most important things in the first three scenes.
IndieDoroid escribióI tried going through here:
spine-unity Runtime Documentation
But glad to have found your thread before I pulled out my hair.
I'm sorry to hear that. Were these instructions not helpful?
spine-unity Runtime Documentation: Setting Animations
Or are you missing just the [SpineAnimation]
part? I will add this to the documentation section soon, thanks for the hint!
IndieDoroid escribióA neat little trick is to also create a small Enum. If you have a lot of animations you wish to cycle through.
Then you can ensure you won't have typo errors in the inspector!
How do you get typo errors in the Inspector? [SpineAnimation] string animationName
provides you with a combo box where you can select each animation from a list, there is no way to misspell anything. If you don't want to use the [SpineAnimation] string
, you could also use one of more AnimationReferenceAssets
, as shown in Getting Started/3 Controlling Animation Continued
.
Thanks for the feedback, we will improve the documentation!
We have now improved the documentation pages, now mentioning string property attributes where available:
spine-unity Runtime Documentation: Skeleton
We are also demonstrating AnimationReferenceAssets
as a string alternative in code here now:
spine-unity Runtime Documentation: Setting Animations
We also added a section listing available property attributes here:
spine-unity Runtime Documentation: Scripting String Property Attributes
We hope that this has removed some more hurdles when beginning to use the spine-unity runtime. Please let us know if any important information is still missing that should be mentioned for beginners. Thanks again for your feedback!