holymolar

Hi folks,

Would love to find out if this is possible (in editor mode).

Looking to use custom Timeline tracks in Unity 2019.2 which can subscribe to the events one would set in the Spine editor. I'm able to make EventDataReferenceAssets very smoothly from the exported Spine AnimationSkeleton. The Unity timeline tracks are very convenient and should listen to these spine animation events. How?

So far cannot get to the event subscriber to react. Primarily interested in getting these events to fire in edit mode when scrubbing the Unity Timeline.

The code on the reference page doesn't seem to work.:
Events - Spine User Guide

A standard Unity Timeline animation track (not a spine animation state track) will sense a standard animation event set in the Unity animation reference. However, looking to extend the Esoteric Unity Timeline track instead so it can sense the events set in the Spine application.

Anyone have any hints?
/// <summary>
/// The Unity Timeline behavior mixer which would react to spine animation events
/// </summary>
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
base.ProcessFrame(playable, info, playerData);

SpineActor spineActor = (SpineActor)actor;
if (spineActor.skeletonAnimation == null)
return;

var spineComponent = spineActor.skeletonAnimation;
var skeleton = spineComponent.Skeleton;
var state = spineComponent.AnimationState;


spineComponent.state.Event -= SkeletonEvent;
spineComponent.state.Event += SkeletonEvent;

....
}


/// <summary>
/// Expecting this to fire this when a spine editor placed event is tripped
/// </summary>
private void SkeletonEvent (TrackEntry trackEntry, Spine.Event e)
{
Debug.Log("%%%%%% TrackEntry["+ trackEntry.ToString() +"] Event["+ e.Data.Name +"] %%%%%%");
}
holymolar
  • Posts: 16

Harald

I'm not completely sure what you are trying to achieve.
Do you mean to hook it up with this Signal Receiver described here?
Or do you just want to receive any events sent from the skeleton's animations in the normal delegate callback way?

Please note that you can also use the sample component SpineEventUnityHandler and attach it to the SkeletonAnimation GameObject to listen to any events and trigger custom behaviour in Unity's event handler way.
User avatar
Harald

Harri
  • Posts: 1500

holymolar

Big thanks for the reply.

Yes, the normal delegate callback way.

Curious of the way Unity Timeline Signal Receivers can receive Spine animation events. That sounds like it could be a workaround.

but..

The normal delegate callback way allows the animator to set the timing of the events from within the Spine editor no matter what kind of media its exported into. However, the Spine event doesn't seem to fire, even though the exported event is detected by the scripts.




Would there be a reason why the state.Event delegate would not be invoked?

Also tried applying [ExecuteAlways] in the on the SpineEventUnityHandler so would run the start method in editor, but the Spine events do not fire.

In the PreviewEditModePose function of SpineAnimationStateMixerBehaviour, there's a dummyAnimationState which gets a new AnimationState. Do the Spine Event delegates copy over too?

This set of code gets called every frame with an editor timeline play, but the event list is hardcoded to null. When setting this to a list, no event fires yet.

SpineAnimationStateMixerBehaviour.cs
holymolar
  • Posts: 16

Harald

holymolar wrote:Curious of the way Unity Timeline Signal Receivers can receive Spine animation events. That sounds like it could be a workaround.
It should not need any workarounds, the normal callback should be called as usual.
holymolar wrote:However, the Spine event doesn't seem to fire, even though the exported event is detected by the scripts.
Then we should find the cause if this issue. I have made a quick test and received e.g. the Footstep event from Timeline playback as usual.

Did you perhaps change any of the TrackEntry event thresholds?
Since I assume that you did not change any of these track settings, could you please send us a minimal zip package of your Unity project that still shows the problem? Then we can have a look at what's going wrong.
User avatar
Harald

Harri
  • Posts: 1500

holymolar

Thanks again for the reply.

Yes, is true, track settings were not changed. A minimum timeline available with just an event in the Spine State Animation track. Did not include Spine Runtime or Timeline package. Did include the Spine editor export and scene setup (will need both those in the test environment). No custom scripts needed for minimum repro.

Same problem happens when there's a timeline on spineboy's run animation with the footstep spine event (does not fire when timeline scrubbing or timeline editor playback).


Repro:
Press the play function on the timeline or scrubbing through the timeline by hand (Not pressing the scene play button).
Observe that the event does not fire.



Note:
Pressing the scene play button, the event fires as expected. However, we're looking to see the event fire in editor mode during timeline playback and scrubbing.
You do not have the required permissions to view the files attached to this post.
holymolar
  • Posts: 16

Harald

holymolar wrote:Pressing the scene play button, the event fires as expected. However, we're looking to see the event fire in editor mode during timeline playback and scrubbing.
I'm sorry, I misunderstood you there, I thought you meant it didn't fire after pressing the Play button. I will have a look at it, thanks for reporting!

---

I have created an experimental modified version of the SpineAnimationStateMixerBehaviour script, which now issues events in the editor as well. However, it issues events also when scrubbing back and forth through the Timeline, raising many events (is this the desired behaviour?).

Additionally, the workaround still only works for a single track, not multiple tracks as is the general problem described in this issue ticket: [unity] Timeline multi-track scrubbing not working · #1313
You do not have the required permissions to view the files attached to this post.
User avatar
Harald

Harri
  • Posts: 1500

holymolar

Huge thanks for that code modification!

Confirmed working in editor Timeline [Play] as expected. However like you're saying...

Scrubbing manually forwards or backwards seems to fire the single event somewhat arbitrarily and a couple times.
Scrubbing backwards unexpectedly fires a lot of events.

Ideally the scrubbing would fire the event only once per scrub direction (assuming there was one event in the clip) and approx in the time that would be expected to fire.
holymolar
  • Posts: 16

Harald

Yes, that is unfortunate. I'm afraid we will have to fix the whole Timeline scrubbing behaviour first (as mentioned in the issue ticket above).
User avatar
Harald

Harri
  • Posts: 1500

holymolar

Thanks for all that and looking forward to all the innovations Spine provides!

Our quick fix (hack) was to include a timeline head delta which seems to make the scrubbing by excluding the backward scrubbing event triggering edge case.
holymolar
  • Posts: 16

Harald

That's brilliant, thanks very much for sharing!
User avatar
Harald

Harri
  • Posts: 1500


Return to Unity