Bekko

hi,

is it possible to control the mixing between 2 animations by accessing the Alpha slider in spine.

basically to mix the alpha at 50% and stay as long as I want

TrackEntry alpha?

help
Bekko
Posts: 13

Harald

Yes, you can use separate tracks and then blend between them via the TrackEntry.Alpha property.
Additionally, when setting TrackEntry.TimeScale = 0 plus TrackEntry.TrackTime = <target time position in 0..1> you can stop playback and directly set the timepoint of the still-frame of each track.

The following working component code shows how this can be acomplished, having three sliders - one slider for blending between the two layers of animations and two more for each track's TrackTime:
using UnityEngine;

public class MixAnimDirectControl : MonoBehaviour {

private Spine.Unity.SkeletonAnimation skeletonAnimation;
private Spine.TrackEntry track0;
private Spine.TrackEntry track1;

[Range(0, 1)]
public float blendToTrack1 = 0.0f;
[Range(0, 1)]
public float trackTime0 = 0.0f;
[Range(0, 1)]
public float trackTime1 = 0.0f;

void Start() {
skeletonAnimation = this.GetComponentInParent<Spine.Unity.SkeletonAnimation>();
track0 = skeletonAnimation.AnimationState.SetAnimation(0, "jump", true); // simple example, works with the Raptor Spine sample character
track1 = skeletonAnimation.AnimationState.SetAnimation(1, "walk", true);

track0.TimeScale = 0.0f;
track1.TimeScale = 0.0f;
}

void Update() {
ApplyTrackParameters();
}

void ApplyTrackParameters() {
//track0.Alpha = 1 - blendToTrack1; // not needed since it's the first track
track1.Alpha = blendToTrack1;

track0.TrackTime = trackTime0;
track1.TrackTime = trackTime1;
}
}
User avatar
Harald

Harri
Posts: 147

Bekko

thanks!

[edit]

I've edited it, it works fine !!
using UnityEngine;

public class MixAnimDirectControl : MonoBehaviour
{

private Spine.Unity.SkeletonAnimation skeletonAnimation;
private Spine.TrackEntry track0;
private Spine.TrackEntry track1;
private Spine.TrackEntry track2;
public Transform target;
private float m_Currentangle;
public float m_Range = 45f;

[Range(0, 1)]
public float blendToTrack1 = 0.0f;

void Start()
{
skeletonAnimation = this.GetComponentInParent<Spine.Unity.SkeletonAnimation>();
track0 = skeletonAnimation.AnimationState.SetAnimation(0, "rire", true);
track0.Alpha = 0; // simple example, works with the Raptor Spine sample character
track1 = skeletonAnimation.AnimationState.SetAnimation(1, "rire2", true);
track1.Alpha = 0;
track2 = skeletonAnimation.AnimationState.SetAnimation(2, "rire3", true);
track2.Alpha = 0;

}

void Update()
{
if (target.localEulerAngles.y >= 0 && target.localEulerAngles.y <= m_Range)
m_Currentangle = (target.localEulerAngles.y) / m_Range;
else if (target.localEulerAngles.y >= m_Range && target.localEulerAngles.y <= m_Range * 2f)
m_Currentangle = (target.localEulerAngles.y - m_Range) / m_Range;
else if (target.localEulerAngles.y >= m_Range * 2f && target.localEulerAngles.y <= m_Range * 3)
m_Currentangle = (target.localEulerAngles.y - m_Range * 2) / m_Range;
else if (target.localEulerAngles.y >= m_Range * 3f && target.localEulerAngles.y <= m_Range * 4)
m_Currentangle = (target.localEulerAngles.y - m_Range * 3) / m_Range;


ApplyTrackParameters();
}

void ApplyTrackParameters()
{
track0.Alpha = 1 - m_Currentangle; // not needed since it's the first track
track1.Alpha = m_Currentangle;

if (target.localEulerAngles.y >= 0 && target.localEulerAngles.y <= m_Range)
{
track0.Alpha = 1 - m_Currentangle; // not needed since it's the first track
track1.Alpha = m_Currentangle;
track2.Alpha = 0;

}
else if (target.localEulerAngles.y >= m_Range && target.localEulerAngles.y <= m_Range * 2f)
{
track0.Alpha = 2 - m_Currentangle; // not needed since it's the first track
track1.Alpha = 1 - m_Currentangle;
track2.Alpha = m_Currentangle;

}


}
}
You do not have the required permissions to view the files attached to this post.
Bekko
Posts: 13

Harald

You modified my sample code a bit too much - you always set the animation at track index 1 instead of one animation at index 0, the other at index 1:
track0 = skeletonAnimation.AnimationState.SetAnimation(1, "rire", true);
track1 = skeletonAnimation.AnimationState.SetAnimation(1, "rire2", true);
It should instead be:
track0 = skeletonAnimation.AnimationState.SetAnimation(0, "rire", true);
track1 = skeletonAnimation.AnimationState.SetAnimation(1, "rire2", true);
Same applies to the block below.

---

Great to hear that it now works! I just wrote the posting a few minutes before you edited the posting above, so you can ignore it in the meantime.
User avatar
Harald

Harri
Posts: 147

Bekko

hey @Harald

thx again, I've noticed an "ease", is there a way to set it to 0?

(Edit)

It’s the “MixDirection” ? i don't think so... Is there a way to set a linear blend ?
You do not have the required permissions to view the files attached to this post.
Bekko
Posts: 13

Harald

There is no easing when you directly set the track Alpha values.

I guess the problem is that you are blending between animations by angle which interpolates positions linearly - what you would like is achieved by using the sine of the angle as input, so replace every occurrance of angle by Mathf.Sin(Mathf.Deg2Rad * angle).
User avatar
Harald

Harri
Posts: 147


Return to Unity