Resetting default Animator Controller

I have watched and re-watched the video on resetting the animator controller. I can not understand what is happening with it, when Sam is talking about parents of the animation / animator.

            var overrideController = animator.runtimeAnimatorController as AnimatorOverrideController;

            if (animatorOverride != null)
            {
                animator.runtimeAnimatorController = animatorOverride;
            }
            else if (overrideController != null)
            {               
                animator.runtimeAnimatorController = overrideController.runtimeAnimatorController;   
            }

for what ever reason my brain won’t let me understand what its doing. If anyone can explain a little more that would be great thanks!!

This is a tricky bit of code… let’s take it piece by piece…
First, we’re getting the current override controller. We’ll need it if we don’t have an animator override in or Weapon Configuration.
Then we check for just that… if we have an animatorOverride, then just set that as the override controller, and we’re done.
But if we don’t have an animator override in our weapon config, and if the animator currently has an override controller (as opposed to the controller assigned in the scene file), then we’re essentially resetting the animator controller back to it’s parent.
It looks confusing, because Unity chose a confusing way to represent the original controller.

I find it’s best to ensure that all of my weapon configurations have an animator override associated with them (even if they are essentialy blank).

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms