CrossFade/Blend Additive Animations?

Hey there,

i have an character with some animations. They are mostly divided into two parts, like:

RunBase and RunTop

IdleBase and IdleTop

Its mainly for the purpose of changing the arm animation while running.
Now my problem: I want to blend or fade the animations into another. Here is my Code so far:

 public Transform shoulder;
    AnimationState RunTop;
    AnimationState IdleTop;
    
    void Start() {
        animation.Stop();

        animation.wrapMode = WrapMode.Loop;


        RunTop = animation["RunTop"];
        RunTop.weight = 1.0f;
        RunTop.wrapMode = WrapMode.Loop;
        RunTop.layer = 11;
        RunTop.blendMode = AnimationBlendMode.Blend;
        RunTop.AddMixingTransform(shoulder);

        IdleTop = animation["IdleTop"];
        IdleTop.weight = 1.0f;
        IdleTop.wrapMode = WrapMode.Loop;
        IdleTop.layer = 10;
        IdleTop.blendMode = AnimationBlendMode.Blend;
        IdleTop.AddMixingTransform(shoulder);
    }


    void Update () {
        PlatformerControllerSinbad controller = GetComponent("PlatformerControllerSinbad") as PlatformerControllerSinbad;

        if (controller.IsMoving())
        {
            animation.CrossFade("RunBase");
            RunTop.enabled = true;
        }
        else
        {
            
            animation.CrossFade("IdleBase", 0.5f);
            RunTop.enabled = false;
            IdleTop.enabled = true;
        } 
    }

The Transform Object “shoulder” is the upper Part of the Body.
Hope some1 can help me. Im grateful for any tip!

Crossfade is made to smooth from one to the other. The same way you are using it for the base, use it for the top. You'll need to have them on the same layer (instead of 10 and 11.)

CrossFade("A") automatically ramps up A, and ramps down the weight of whatever was on the same layer as A.

EDIT: (on response to questions entered as answers)

If you read the animation docs, the default settings are fine. So, you don't have to set weight=1, speed=1, blendMode=blend... . All you need to set is the layer, if not 0. A lot of examples uselessly to set these, to show where you would be able to change speed to 50%, say.

CrossFade by itself really is made to solve the most common situation. Enable is for special circumstances (like you are going into a ragdoll.) The Ex from the docs really does work:

// these three animations are on the same level, and looping:
if(shooting) animation.CrossFade("upperGunAim");
else if(running) animation.CrossFade("upperArmPump");
else animation.CrossFade("upperIdle");

But im just enabling the AnimationState for the upper Part (IdleTop.enabled = true). How im a able to Crossfade those?

And another question. Do i have to set the options for the AnimationState for every UpperBody Animation?

 RunTop = animation["RunTop"];
    RunTop.weight = 1.0f;
    RunTop.wrapMode = WrapMode.Loop;
    RunTop.layer = 11;
    RunTop.blendMode = AnimationBlendMode.Blend;
    RunTop.AddMixingTransform(shoulder);

    IdleTop = animation["IdleTop"];
    IdleTop.weight = 1.0f;
    IdleTop.wrapMode = WrapMode.Loop;
    IdleTop.layer = 10;
    IdleTop.blendMode = AnimationBlendMode.Blend;
    IdleTop.AddMixingTransform(shoulder);

Or is there an easier and maybe better way to do this? Because i will have 3 more seperate Animations.

So by setting things up like:

RunTop = animation["RunTop"];
RunTop.AddMixingTransform(shoulder);

It also affects the animation.Crossfade (so that animation.CrossFade(“RunTop”) is just a CrossFade for the upper Body part?).
And by setting up different Layers for the “Top” Animations i can seperately control the weights in the upper and lower body half?

Alright…i guess i got it working with your help. This is my Script:

public Transform shoulder;
AnimationState RunTop;
AnimationState IdleTop;
AnimationState DrawSwords;
AnimationState HandsClosed;
void Start() {
    animation.Stop();

    animation.wrapMode = WrapMode.Loop;

    HandsClosed = animation["HandsClosed"];
    HandsClosed.weight = 1.0f;
    HandsClosed.layer = 1;
    HandsClosed.wrapMode = WrapMode.ClampForever;
    HandsClosed.blendMode = AnimationBlendMode.Blend;
    HandsClosed.AddMixingTransform(shoulder);

    DrawSwords = animation["DrawSwords"];
    DrawSwords.weight = 1.0f;
    DrawSwords.layer = 2;
    DrawSwords.wrapMode = WrapMode.Once;
    DrawSwords.blendMode = AnimationBlendMode.Blend;
    DrawSwords.AddMixingTransform(shoulder);

    RunTop = animation["RunTop"];
    RunTop.weight = 1.0f;
    RunTop.layer = 1;
    RunTop.wrapMode = WrapMode.Loop;
    RunTop.blendMode = AnimationBlendMode.Blend;
    RunTop.AddMixingTransform(shoulder);

    IdleTop = animation["IdleTop"];
    IdleTop.weight = 1.0f;
    IdleTop.layer = 1;
    IdleTop.wrapMode = WrapMode.Loop;
    IdleTop.blendMode = AnimationBlendMode.Blend;
    IdleTop.AddMixingTransform(shoulder);

    int jumpingLayer = 3;
    AnimationState jump = animation["JumpStart"];
    jump.layer = jumpingLayer;
    jump.wrapMode = WrapMode.Once;

    AnimationState jumpFall = animation["JumpLoop"];
    jumpFall.layer = jumpingLayer;
    jumpFall.wrapMode = WrapMode.ClampForever;

    AnimationState jumpLand = animation["JumpEnd"];
    jumpLand.layer = jumpingLayer;
    jumpLand.wrapMode = WrapMode.Once;

}

void Update () {
    PlatformerControllerSinbad controller = GetComponent("PlatformerControllerSinbad") as PlatformerControllerSinbad;

    if (controller.IsMoving())
    {
        animation.CrossFade("RunBase");
        //RunTop.enabled = true;
        animation.CrossFade("RunTop");
    }
    else
    {
        
        animation.CrossFade("IdleBase", 0.5f);
        //RunTop.enabled = false;
        animation.CrossFade("IdleTop", 0.8f);
    }

    if (Input.GetKeyDown("e"))
    {     
        animation.CrossFade("DrawSwords");
    }
}

void DidJump()
{
    animation.Play("JumpStart");
    animation.PlayQueued("JumpLoop");
}

void DidLand()
{
    animation.Stop("JumpLoop");
    animation.Play("JumpEnd");
    animation.Blend("JumpEnd", 0);
}

void DidDraw()
{
    HandsClosed.enabled = !HandsClosed.enabled;
}

I have set the UpperBody Animations on Layer 1 and the Run / Idle Animation on Layer 0.
Is this how it should be done? (except the blendMode / weight settings)…

Because now i got another odd problem. The “DrawSwords” Animation is getting played when i press “e” - but only Once in the whole "GameSession. So if i press “e” again it seems like it is just playing the first frame of the animation.
Is there something wrong with my settings? The Animation works fine, ive already tried it in Loop Mode.

Thanks for all the help so far!