When event triggered, I want to play audio and control some animator parameters
How to receive event spine animation on unity
To receive events from a Spine animation in Unity and perform actions such as playing audio and controlling animator parameters, you can follow these steps:
Set Up Spine Events: In the Spine editor, create events at the desired frames in your animation. These events will be used to trigger actions in Unity.
Use the
SkeletonAnimation
Component: Attach theSkeletonAnimation
component to your GameObject in Unity. This component will allow you to receive events from the Spine animation.Subscribe to AnimationState Events: In your Unity script, subscribe to the
AnimationState.Event
to handle events. You can do this by adding a method to handle the event, like so:public class SpineEventHandler : MonoBehaviour { public SkeletonAnimation skeletonAnimation; public AudioSource audioSource; public AudioClip audioClip; public Animator animator; void Start() { skeletonAnimation.AnimationState.Event += HandleAnimationStateEvent; } private void HandleAnimationStateEvent(TrackEntry trackEntry, Spine.Event e) { if (e.Data.Name == "YourEventName") { PlayAudio(); ControlAnimatorParameters(); } } private void PlayAudio() { audioSource.clip = audioClip; audioSource.Play(); } private void ControlAnimatorParameters() { animator.SetBool("YourParameter", true); } }
Play Audio and Control Animator: In the
HandleAnimationStateEvent
method, check for the specific event name and perform the desired actions, such as playing an audio clip and setting animator parameters.
This setup allows you to react to Spine animation events in Unity by playing audio and controlling animator parameters.
rmx As you know, the Spinebot is on this forum and will give you an immediate answer, but you will not get a good answer if your question is not very specific, so please be detailed about your requirements, including the fact that you are using SkeletonMechanim
, to make it easier for us to give you an accurate answer.
When using SkeletonMecanim
, events are stored in each AnimationClip
and are raised like other Unity animation events. For more information see the following sections of the documentation:
https://esotericsoftware.com/spine-unity-main-components#SkeletonMecanim-Events