Moving a Unity Animator component to its parent

Tweet about this on TwitterShare on FacebookShare on RedditShare on Google+Email this to someonePin on Pinterest


In VALA I’ve been animating a cut-scene, and made the silly mistake of putting my Animator component on the character instead of on a root object. This means that the Animator isn’t able to move anything except the character (because they are not in the same hierarchy).

In the image below, my Animator was on Scientist, instead of ScientistRoot, meaning that I couldn’t use it to animate ScientistTerminal when he touches it.

animator

So here is a quick tip to move the Animator to the root GameObject – which Unity doesn’t support, but really should.

First, copy the Animator component from the child to the parent (in my case from Scientist to ScientistRoot. At this point, if you open an Animation in Unity, all of the lines will be yellow because the reference is broken since the components are referenced by name, and the hierarchy has changed.

animator2

To fix these references, open up the Animation that the Animator uses (or each Animation if it has multiple) in Visual Studio or whatever text editor you use. In the YAML that opens up, you’ll find something like:
    path: Hips/Spine/Spine1/Spine2/Neck/Neck1/Head/Jaw
Which is a path to the component that it refers to. All you need to do now is change all references like that to be relative to the new parent that has the Animator.

In my case, I just moved the Animator up one level, so I just need to change it to:
    path: Scientist/Hips/Spine/Spine1/Spine2/Neck/Neck1/Head/Jaw

To do that do a Find And Replace All, searching for path: Hips and replace with path: Scientist/Hips.

Now just open up Unity again and it should just work.

Tweet about this on TwitterShare on FacebookShare on RedditShare on Google+Email this to someonePin on Pinterest