Search Unity

Resolved Cannot Change Animator Layer Settings in Script

Discussion in 'Animation' started by magique, Sep 14, 2023.

  1. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I have some code that creates the Animator Controller from a scriptable object and it has been working great so far. I've done just about everything from states, sub-states, blend trees, transitions, etc. Now, I'm trying to add a new layer and set the layer's properties. The layer itself is created fine and so are the animator states inside the layer. However, when I try to change layer settings such as avatarMask and defaultWeight, they won't take.

    When I breakpoint debug, the value I'm trying to assign is valid, but after stepping over the assignment code, the layer setting value is unchanged. Here is the code I am using:


    Code (CSharp):
    1.             int layerIndex = _controller.layers.Length;
    2.             _controller.AddLayer(LAYER_TURNING);
    3.             _controller.layers[layerIndex].avatarMask = locomotionAnimations.turningLayer.avatarMask;
    4.             _controller.layers[layerIndex].defaultWeight = locomotionAnimations.turningLayer.maskWeight;
    Any ideas why these layer settings cannot be set like this?

    I'm using Unity 2021.3.27f1.
     
    Last edited: Sep 14, 2023
  2. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030