- Đã chỉnh sửa
Unity - Add Event listener from SkeletonAnimator
Hi.
I am currently using Instantiate (Mecanim) on Unity.
But I can't find a way to add a event listener like "skeletonAnimation.state.Event += Event" in script.
SkeletonAnimator has no functions for that.
So, How do I add a listener on animation event??
I couldn't found a solution for this in this forum.
Thanks in advance :love: :love:
Works like Mecanim. Has same limitations as Mecanim. Events are dispatched using SendMessage and can only contain one parameter type.
Is this documented anywhere? Mecanim is set up so you select a method to directly call something on your script. Does spine look for a specific string param method that we need to create?
Mecanim uses SendMessage. Events are included in the placeholder .anim file when generating the mecanim controller and are sent through UnityEngine.Animator
Feel really stupid for asking again but where are they sent and are they sent with the name of the event defined in the spine animation?
I know how to create them manually and hook them up in unity/mecanim, but I would assume spine is already creating the event and send message functionality to be listened to somehow?
If I have a class that needs to listen for it I'm just not seeing how to.
Also, really important.. do the events fire with correct timing if I change my animation speed (introduced in Unity 5.1) to say .5 which basically makes the animation play at half speed correctly and reliably?
Hey Mitch
Could you elaborate a bit here? What Spine param is passed (int, float, string) as the one param allowed by SendMessage?
Hi,
I'm stuck on this old problem. I made a creature that has an eat animation, with spine events being called "Eat_Start" and "Eat_Stop".
I'm using it with the Skeleton Mecanim component. From what I understand, this is being sent as "SendMessage" with the "Eat_Start" and "Eat_Stop" messages.
Now I want to invoke a UnityEvent (play/stop a particle system) when the Spine rig does the "Eat_Start" Animation Event.
Do I need to create a function on a script with the name Eat_Start()? It doesn't seem very dynamic, when creating multiple events.
Also if I have two creatures, wouldn't both receive this event? How can this even be used?
Do I need to skip the Mecanim/Animator component completely and setup my own system to handle the spine events?
I find that the Animator is very easy to set up, with the transitions and parameters, but if it has this limitation, it seems kinda bad.
Thanks
Ok I realized that SendMessage is only called on every MonoBehaviour in the same game object as the MecAnim, so it works.
But it still would be better not having to hardcode a function for each parameter.
As usual, you can find this in the official spine-unity documentation pages:
spine-unity Runtime Documentation: SkeletonMecanim Events
Please always consult this documentation page first, so that you can save yourself some time and trouble.
You are absolutely right that having to add a method for every event is not very nice. Unfortunately we just add Unity's own AnimationEvent
to each AnimationClip
that is generated upon import. It's in the hands of the Mecanim playback system to issue the event then, so we are bound to Unity's API.
BTW: I just noticed that the outgoing link to the Unity documentation page was broken, I just fixed it to point to the corresponding Unity docs page again.
Thanks, I studied the documentation, but I mostly read here: Coding for Spine Events and AnimationState callbacks which had very little information.
This page also has a broken link to the Unity docs.
Even if it's the same methodology as Unitys own events, it would be helpful with a little snippet, and maybe a clarification that it requires methods and cannot be dynamic. Not sure, but that's what confused me.
Thanks!
nicmar đã viếtThanks, I studied the documentation, but I mostly read here: Coding for Spine Events and AnimationState callbacks which had very little information.
This page also has a broken link to the Unity docs.
Thanks for the info, I just removed the Mecanim section text from the Coding for Spine Events and AnimationState callbacks
page and added a link to the spine-unity page, where the link is now correct.
nicmar đã viếtEven if it's the same methodology as Unitys own events, it would be helpful with a little snippet, and maybe a clarification that it requires methods and cannot be dynamic. Not sure, but that's what confused me.
Thanks for the input! There is now example code that demonstrates it:
spine-unity Runtime Documentation: SkeletonMecanim Events