Animator stateMachines are cool, but don’t provide solution for everything A simple thing would be to provide an animationClip from the outside somehow (for example, when the clip is bound to some object in the scene, not the character itself). My idea was this - create a playableGraph with the AnimatorControllerPlayable blend it using an animationMixer with something else, output that to the original controller. It does work, however there seems to be a huge performance penalty. The controller’s statemachine is quite complex, contains many blends and layers, but there is no performance problem, until I add the extra animation mixer.
Here’s the code I am using now
animator.playableGraph.Destroy();
m_playableGraph = PlayableGraph.Create();
var externalOutput = AnimationPlayableOutput.Create(m_playableGraph, "ExternalAnimator", animator);
m_animationMixer = AnimationLayerMixerPlayable.Create(m_playableGraph, 3);
externalOutput.SetSourcePlayable(m_animationMixer);
var humanAnimatorPlayable = AnimatorControllerPlayable.Create(m_playableGraph, animator.runtimeAnimatorController);
m_animationMixer.ConnectInput((int)MixerInput.HumanAnimator, humanAnimatorPlayable, 0, 1);
// Plays the Graph.
m_playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
activityAnimationLayer = new AnimationControllerLayer((int)MixerInput.ActivityAnimator, m_animationMixer);
speechAnimationLayer = new AnimationClipLayer((int)MixerInput.SpeechClip, m_animationMixer);
m_animationMixer.SetLayerAdditive((int)MixerInput.SpeechClip, true);
m_playableGraph.Play();
The Animator component culling seems to not have any effect on the performance after the custom graph is injected (from looking at the profiler before and after, and moving the camera).
Here are screenshots of the profiler, the highlighted part in the graph shows the difference when the custom graph is applied and not
I’ve also tried a version where I’d take the playableGraph from the controller, and try to swap the output playable - but that seemed to have no effect at all.
Am I missing something? Is there any other way how I could achieve blending a custom animation in?