trafcio

Hi,

it is pretty hard for me to describe problem, so I'll use an example first :)

I have two animations for a character: idle and angry. I use unity timelines and have a smooth transition between them. The angry animation is too exaggerated. Meanwhile, when I mix from idle to angry I see a transition position where angry looks really nice (about halfway).
Is there a way to play somehow: 50% of angry animation?

What we now do is manually adjust animations in Spine, but such an option would benefit us heavily.
I do not suppose there is something in Unity tools, but if you could show some code snippet or class where I can look for the solution it would be great.

Cheers,
Kullanıcı avatarı
trafcio
  • Mesajlar: 32

Harald

Do you mean 50% TrackEntry alpha? Please note that TrackEntry.Alpha only works well if you have another track at a lower track index (e.g. a base track on track index 0) as well.
Kullanıcı avatarı
Harald

Harri
  • Mesajlar: 4014

trafcio

Cool,

it is what I was looking for.

If somebody would like to implement it to Unity Timelines you need to do some changes. The most important ones are:

In SpineAnimationStateMixerBehaviour.cs
[...]
if (clipData.animationReference.Animation != null) {
Spine.TrackEntry trackEntry = state.SetAnimation(trackIndex, clipData.animationReference.Animation, clipData.loop);

trackEntry.EventThreshold = clipData.eventThreshold;
trackEntry.DrawOrderThreshold = clipData.drawOrderThreshold;
trackEntry.TrackTime = (float)inputPlayable.GetTime() * (float)inputPlayable.GetSpeed();
trackEntry.TimeScale = (float)inputPlayable.GetSpeed();
trackEntry.AttachmentThreshold = clipData.attachmentThreshold;
trackEntry.HoldPrevious = clipData.holdPrevious;
// ========== ADD LINE ===========
trackEntry.Alpha = clipData.customMixWeight; // <--- THIS

if (clipData.customDuration)
trackEntry.MixDuration = clipData.mixDuration;

timelineStartedTrackEntry = trackEntry;
}
[...]
dummyAnimationState.Update(0);
dummyAnimationState.Apply(skeleton);
} else {
if (toAnimation != null)
// ========== CHANGE LINE ===========
toAnimation.Apply(skeleton, 0, toClipTime, clipData.loop, null, clipData.customMixWeight, MixBlend.Setup, MixDirection.In); // <--- THIS
}
skeleton.UpdateWorldTransform();
You need to also add properties (e.g. customMixWeight) according to your needs in SpineAnimationStateDrawer.cs so it will look similar to:

Kullanıcı avatarı
trafcio
  • Mesajlar: 32

Harald

Glad to hear you've figured it out! Thanks for sharing your code, always much appreciated!
A side note: You have missed to assign the value also in the editor code section if (!isAnimationTransitionMatch) {..} in SpineAnimationStateMixerBehaviour: ~line 290. It's nothing crucial though.

We have a decided to officially add the Alpha parameter, new commits have been pushed to both 4.0 and 4.1-beta branches. From the changelog:
CHANGELOG.md yazdı:Timeline clips now offer an additional Alpha parameter for setting a custom constant mix alpha value other than 1.0, just as TrackEntry.Alpha. Defaults to 1.0.
New Timeline UPM packages are available for download here as usual:
Spine Unity Download
We didn't add a Use Custom Mix Weight parameter as the default value of 1.0 keeps the default behaviour and mirrors the TrackEntry field directly. We understand of course that some users might prefer different controls and names.
Kullanıcı avatarı
Harald

Harri
  • Mesajlar: 4014

trafcio

Cool! Great info.

We'll definitely update to the newest version in the near future.

Thanks :)
Kullanıcı avatarı
trafcio
  • Mesajlar: 32


Dön Unity