• Unity
  • Spine Events - No longer work in Unity

  • Đã chỉnh sửa
Related Discussions
...

Hi @Harald,

I LOVE the folder option for Spine Events, helps keep everything organized. But it seems I can't call the methods in Unity anymore. How can I fetch the folder path in the method call? 😢

I attached the usual way I call it via C#, that no longer works with folders 🙁

Any suggestions would be helpful! 🙂

How did you originally hook up the method SpineEventStandPunch2() so that it got called?

The recommended way of handling events in Spine-Unity is the one shown in the example scene Spine Examples/Getting Started/2 Controlling Animation. There you can find the example component HandleEventWithAudioExample attached at the sound GameObject.

You first register your event callback method:

skeletonAnimation.AnimationState.Event += HandleAnimationStateEvent;

HandleEventWithAudioExample.cs#L64

And then in the callback method, you can check which type of event was issued:

private void HandleAnimationStateEvent (TrackEntry trackEntry, Event e) { ... }

HandleEventWithAudioExample.cs#L67-L74

Oof that code goes way over my artist head :think: :scared: :wounded:

SpineEventStandPunch2 is the Spine Event name. It gets a keyframe in Spine.

Currently SpineEventStandPunch2 is also a method name in my C# script. That method gets called when Unity detects the SpineEventStandPunch2 event from the animation controller.

This simple way of fetching the Spine Event has worked perfectly for my non-coder brain. Please don't change this alternative workflow haha. Having folders is nice, but it's not worth jumping through high level coding hoops. I don't have time to change my Unity code now, got too much other stuff to do. 🙂

If punch is in a folder named punches, the event name at runtime will be punches/punch. You could strip off the folder(s) prefix, or replace / with some other characters so you can map it to a method name, eg punches_punch().

I just noticed that you were using SkeletonMecanim, my fault.

When folders were used, the called method name was actually broken. I have just committed a bugfix and uploaded new unitypackages:
Spine Unity Download

The new version now supports a Spine Preferences entry whether to include folder names in the called event method name or not:

Mecanim Bake Settings
Include Folder Name in Event
"When enabled, Mecanim events will call methods named 'FolderNameEventName', when disabled it will call 'EventName'."

As the name "Mecanim Bake Settings" suggests, this setting has its effect when generating the animation clips, so you have to click Force Update Animation Clips at the _SkeletonDataAsset to have any effect.

OOOH! Thanks so much man! :love:

Update 2
Ok got it to work. We just need to checkmark "Flatten Path" in the Spine ~> Export ~> Pack Settings 8)

Update 1
I think I'm blind.. But I don't see "Mecanim Bake Settings" anywhere. 😢

Look elsewhere:

Edit -> Preferences -> Spine

This applies to the whole project, otherwise there would be no way to select baking style when implicitly baking animation clips at first drag & drop of a SkeletonDataAsset to a scene.

Ah dangit! Not used to using that part of Unity lol...