• Unity
  • SpineEventUnityHandler

  • Düzenlendi
Related Discussions
...

Hi.
Could you help me with this component? I set it up but it doesn't work at all. What am I doing wrong?

As I understand it, it should run the function I put into the field once Spine event "handle" appears.


Also I tried to subscribe to event from code and failed too

Here is my code, I get it from documentation:

private void Start()
    {

        eventSkeleton.AnimationState.Event += HandleEvent;

        eventSkeleton.AnimationState.Start += delegate (Spine.TrackEntry trackEntry) {
        // You can also use an anonymous delegate.
        Debug.Log(string.Format("track {0} started a new animation.", trackEntry.TrackIndex));
        };
        eventSkeleton.AnimationState.End += delegate {
        // ... or choose to ignore its parameters.
        Debug.Log("An animation ended!");
        };
    
}

private void HandleEvent(Spine.TrackEntry trackEntry, Spine.Event e)
{
    Debug.Log("HandleEvent   "+e.Data.Name);    
    // Play some sound if the event named "footstep" fired.
    
}

Here I'm never getting message in the log from HandleEvent

Please help. Any way from these too will work for me.


I use runtime 4.0 and Spine 4.0.58
Unity 2020.3.20f1

Hey krutovig - your code sample looks correct. By chance are you using SkeletonMecanim and not SkeletonAnimation? SkeletonMecanim has a special way of handling events: spine-unity Runtime Documentation: SkeletonMecanim Events

If you are using SkeletonAnimation, and the SpineEventUnityHandler component, are you placing the SpineEventUnityHandler component on the same gameobject as your SkeletonAnimation?

Yes, I'm using skeleton animation not mechanism
And it's on the same object. If it will be placed somewhere else I never get the dropdown list of events you can see on screenshot.

I can see nothing obviously wrong with your code. Are you sure that your played animation really has any events? You could attach the debugger to Unity and set a breakpoint at AnimationState.cs : line 1364 to see if it ever gets there.