I am writing some editor extensions which setup big complex mechanim blend trees and state machines. I have no problem creating layers, states, and attaching motions to blend trees, etc… However, I can not for the life of me find anywhere that allows me to setup a Motion’s speed setting. I can change it in the inspector but can’t find an api for it.
1 Like
Bump !!!
After you’ve added motions to the blend tree - via myBlendtree.AddChild(myMotion) - grab a copy of the children array, set the timeScale (i.e. speed) and set the children array with your copy. This method assumes that the children indices are in the order in which you add them. Some code (from my project) that works:
/* Create blend tree for run, using ref to AnimatorController. 'runForwardsMotion' and 'runBackwardsMotion' are of type Motion and
are set from the scriptable object to the same run_forward_loop animation (which is why I'm setting the speed to -1.0f for moving backwards.
*/
controller.CreateBlendTreeInController("RunBlendTree", out runBlendTree);
runBlendTree.blendType = BlendTreeType.Simple1D;
runBlendTree.blendParameter = "LocalMoveDirFwd";
runBlendTree.useAutomaticThresholds = false;
runBlendTree.AddChild(runForwardsMotion, 1.0f);
runBlendTree.AddChild(runBackwardsMotion, -1.0f);
ChildMotion[] childMotion = runBlendTree.children;
childMotion[0].timeScale = 1.0f;
childMotion[1].timeScale = -1.0f;
runBlendTree.children = childMotion;
2 Likes