Set Animator Controller Layer Weight

Hey there. Working on a project heavy on animation. I have two animation layers in the animator, the base layer and a second layer playing an additive animation. I want to animate this additive layer’s weight over time on an animation clip.

I’m trying to figure out a way set one layer’s weight with a float, but I haven’t been able to affect the second animation layer at all. Do I need to call the animation layer before the GetLayerIndex? Is there a class that would better help me achieve this? I’ve attached my script below. Any guidance would be appreciated.

public float animWeight = 0.5f;
private Animator anim;

// Use this for initialization
void Start () {
}

void Update ()
{
	anim.SetLayerWeight(anim.GetLayerIndex("AnimationLayer2"), animWeight);
}

I managed to get the script to work, by referencing the SetLayerWeight layer in void Start, then setting the layer again in Update. I still don’t think this is the cleanest way to do it but it definitely works.


public float animWeight = 0.5f;
public Animator anim;

void Start () {

		anim.SetLayerWeight (2, animWeight);

}

void Update ()
{
	anim.SetLayerWeight(anim.GetLayerIndex("AnimationLayer2"), animWeight);
}

}