I’ve been working with mecanim scripting; switching in and out different types of animations using the Animator Override Controller. This worked fine on its own however I also needed to edit the transitions before and after using the UnityEditor.Animations API, this is due to some animations needing a longer duration or cutting them short to blend correctly dependent on the overridden animation my usage shown below:
UnityEditor.Animations.AnimatorStateTransition forwardsAttackTransitionEnter;
UnityEditor.Animations.AnimatorStateTransition backwardsAttackTransitionEnter;
animatorOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
animator.runtimeAnimatorController = animatorOverrideController;
UnityEditor.Animations.AnimatorController animationController = animatorOverrideController.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
foreach(var anyStateTransition in animationController.layers[0].stateMachine.anyStateTransitions)
{
if (anyStateTransition.name == "forwardsAttackTransitionEnter") forwardsAttackTransitionEnter = anyStateTransition;
if (anyStateTransition.name == "backwardsAttackTransitionEnter") backwardsAttackTransitionEnter = anyStateTransition;
}
forwardsAttackTransitionEnter.hasExitTime = weaponData.weaponDictionary[currentWeapon].hasExitTimeEnter;
forwardsAttackTransitionEnter.exitTime = weaponData.weaponDictionary[currentWeapon].exitTimeEnter;
forwardsAttackTransitionEnter.duration = weaponData.weaponDictionary[currentWeapon].transitionDurationEnter;
forwardsAttackTransitionEnter.offset = weaponData.weaponDictionary[currentWeapon].transitionOffsetEnter;
animatorOverrideController["SwordSwing"] = weaponData.weaponDictionary[currentWeapon].weaponforwardAnim;
This works “okay” in the editor (the animator skips for a second as the new transition data is entered) but building this unfortunately won’t work as the Unity Editor namespace isn’t included for standalone builds.
Is there a way to get this code to work in a build or a similar way to get this done using the normal API, if not are there any assets that expose the animator run-time variables like this, or any other ways to implement what I’m trying to achieve?
Thanks for your time
- Aaron