Recently , I was trying to figure out how to make animations played in Unity's editor mode.
I tried to play animations by using PlayableAPI and "ExecuteAlways" attribute(make sure the script will runs correctly in editor mode).And when I was attempting to using "AvatarMask" for Layering animations,I found this API didn't work.
codes and Unity scene are below
public void Play()
{
IKSwitch = true;
_anim.enabled = true;
SceneView.FocusWindowIfItsOpen<SceneView>();
AnimationLayerMixerPlayable mixer;
try
{
mixer = AnimationLayerMixerPlayable.Create(_graph, 2);
}
catch (Exception e)
{
Debug.Log("Initialize failed, re-initializing.....");
InitGraphAndOutput();
return;
}
//Create Avatar Mask
AvatarMask mask = new AvatarMask();
if (handTransform)
{
mask.AddTransformPath(handTransform, true);
}
//Connect AnimationClipPlayable
mixer.ConnectInput(0, AnimationClipPlayable.Create(_graph, clip), 0, 1);
AnimationClipPlayable empty = AnimationClipPlayable.Create(_graph, clip2);
empty.SetApplyPlayableIK(true);
mixer.ConnectInput(1, empty, 0,1);
mixer.SetLayerMaskFromAvatarMask(1, mask);
//Connect layerMix to output
output.SetSourcePlayable<AnimationPlayableOutput, Playable>(mixer, 0);
_graph.Play();
}
And the appearance of the graph is playing clip2 instead of playing mixed animation as I presumed.
I was expecting that clip2 would only take effect on specified parts of character bones
