Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

AnimationLayerMixerPlayable Problem in 2017.1.0 b5

Discussion in 'Animation' started by JosephHK, May 13, 2017.

  1. JosephHK

    JosephHK

    Joined:
    Jan 28, 2015
    Posts:
    40
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3. using UnityEngine.Animations;
    4.  
    5. public class MixerTest : MonoBehaviour {
    6.  
    7.     [Header("---Layer 0---")]
    8.     public AnimationClip layer0Clip;
    9.     [Header("---Layer 1---")]
    10.     [Range(0f, 1f)]
    11.     public float weight;
    12.     public bool isAdditive;
    13.     public AvatarMask mask;
    14.     public AnimationClip layer1Clip0;
    15.     public AnimationClip layer1Clip1;
    16.     [Range(0f, 1f)]
    17.     public float blendingWeight;
    18.  
    19.     private PlayableGraph graph;
    20.     private AnimationLayerMixerPlayable layerMixerPlayable;
    21.     private AnimationMixerPlayable mixerPlayable;
    22.  
    23.     void Start () {
    24.         graph = PlayableGraph.Create();
    25.  
    26.         AnimationClipPlayable layer0ClipPlayable = AnimationClipPlayable.Create(graph, layer0Clip);
    27.         AnimationClipPlayable layer1ClipPlayable0 = AnimationClipPlayable.Create(graph, layer1Clip0);
    28.         AnimationClipPlayable layer1ClipPlayable1 = AnimationClipPlayable.Create(graph, layer1Clip1);
    29.  
    30.         layerMixerPlayable = AnimationLayerMixerPlayable.Create(graph, 2);
    31.         layerMixerPlayable.SetInputWeight(0, 1f);
    32.  
    33.         layerMixerPlayable.SetLayerMaskFromAvatarMask(1, mask);
    34.  
    35.         mixerPlayable = AnimationMixerPlayable.Create(graph, 2);
    36.         graph.Connect(layer1ClipPlayable0, 0, mixerPlayable, 0);
    37.         graph.Connect(layer1ClipPlayable1, 0, mixerPlayable, 1);
    38.  
    39.         graph.Connect(layer0ClipPlayable, 0, layerMixerPlayable, 0);
    40.         graph.Connect(mixerPlayable, 0, layerMixerPlayable, 1);
    41.  
    42.         AnimationPlayableOutput output = AnimationPlayableOutput.Create(graph, "Animation", GetComponent<Animator>());
    43.         output.SetSourcePlayable(layerMixerPlayable);
    44.  
    45.         graph.Play();
    46.     }
    47.  
    48.     private void Update () {
    49.         layerMixerPlayable.SetLayerAdditive(1, isAdditive);
    50.         layerMixerPlayable.SetInputWeight(1, weight);
    51.         mixerPlayable.SetInputWeight(0, 1f - blendingWeight);
    52.         mixerPlayable.SetInputWeight(1, blendingWeight);
    53.     }
    54.  
    55. }
    56.  


    As shown in the above video, when an AnimationClip in the second layer is blended with a null one, the blending behaviour is weird and discontinuous. While the below video shows what I expected to see.



    Did I do something wrong?
     
    Last edited: May 14, 2017
  2. JosephHK

    JosephHK

    Joined:
    Jan 28, 2015
    Posts:
    40
    Please. I want to know whether it is by design :(
     
  3. Bezzy

    Bezzy

    Joined:
    Apr 1, 2009
    Posts:
    75
    I might not have the right answer, but we have similar issues. We think it might be to do with the idea that every input on AnimationLayerMixer is always trying to mix with SOMETHING that came before it . i.e. if the first animation attached to an AnimationLayerMixer has a weight of < 1, the mixer is trying to mix with whatever preceded it. And in that case, it'd be mixing with... "null".. or TPose, in the case of an animation.

    So in this case, make sure you have a base "aiming pose" or another playable plugged into input zero of the AnimationLayerMixer, and ensure its weight is always 1, before adding on your additive aiming layer into input One
     
    Last edited: Mar 21, 2018
  4. zswad123

    zswad123

    Joined:
    Nov 27, 2019
    Posts:
    2
    I have the same question in unity 2018