I’m making a script which automate character animation tree setup. However I have several issues.
First is default weight. I can’t set default weight for layers.
I use code
attackLayer.defaultWeight = 1.0f;
It’s does nothing. I’m still able to get data from the layer like.
I know this is a very old question, but I couldn’t find a solution online and I had the same issue today. So I figured I might as well post it:
When adding a layer with AnimatorController.AddLayer("New layer");, a defaultWeight of 0 is already assigned to the layer, so changing after the layer is added won’t have any effect. What you need to do is to create the AnimatorControllerLayer first, assign it the weight you want, and then add it to the AnimatorController.
So:
var layer = new UnityEditor.Animations.AnimatorControllerLayer
{
name = "New layer",
defaultWeight = 1f,
stateMachine = new UnityEditor.Animations.AnimatorStateMachine() // Make sure to create a StateMachine as well, as a default one is not created
};
controller.AddLayer(layer);
When I duplicate the ‘AnimatorController’ after the changes has been made, the AnimatorStateMachine in the duplicated one would disappear visually… do you have any idea?