• Unity
  • access the Alpha slider in spine.

Related Discussions
...

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

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; } }

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 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.

hey @[삭제됨]

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 ?

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).

5달 후

made it very smooth, so now it rotates perfectly :
, full code down, the bump is from the spine. I created a quick version to make it available "SpineFAce.zip"

my problem is to also use the Y axes, to get extreme angles from above or from below

@Harald, it seems like there is a limit of alpha track ?

maybe I'm doing it wrong?

Bekko wrote

I created a quick version to make it available "SpineFAce.zip"
my problem, I'm trying to make it full 360, to get extreme angles from above or from below,
but I struggle, it seems like there is a limit of alpha track ?

I cannot yet see what the problem is that you are facing. Could you please describe what your expected outcome is and what you are currently seeing instead?

5일 후

hey @[삭제됨]

I found the problem, I forgot to change that number, yup :shh: I did that! thx for the help

Glad to hear you could resolve the problem, thanks for letting us know!