Search Unity

Can't record key values except at the root of the hierarchy

Discussion in 'Animation' started by JoeStrout, May 1, 2019.

  1. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I'm trying to create an animation on a humanoid character, but the Animation window won't record a key value for anything except the GameObject at the very root (the one with the Animator component). If I try to animate, for example, the "Bip002 L Thigh" joint, it doesn't work:

    • In Record mode, the position and rotation properties are highlighted in red. I use the Rotation tool to rotate the bone. The values change in the Inspector, but no keyframe is added to the animation. And as soon as I move the play head in the Animation timeline at all (even move it over and back), my changes to the rotation disappear and the limb returns to its original position.
    • Also in Record mode, I click in one of the red properties (like X Rotation) and type in a new value. Same thing: no keyframe, value doesn't stick.
    • I right-click on "Rotation" and choose "Add Key." Nothing happens.
    • Using "Add Property" in the Animation window, I manually add Bip002 L Thigh : Rotation as a property. Now I manually add some keyframes, select one of them, and type in a new value. The rotation value shown in the Animation window does not change, and again, when I move the playhead over and back, my change is gone and the leg is back to its original value.
    • I instead select a key frame, then click in the X rotation value shown on the left side of the Animation window itself. I type in a new value, and press return. My new value immediately disappears and is replaced with the original value.
    • That was in Dope Sheet mode. If I switch to Curves mode, I see curves for these properties, and I can edit them (drag points up and down, etc.). But when I click Play to preview it, the limb does not change, and the values do not change. The playhead moves right over the curves while apparently completely ignoring them.
    All that is when I try to animate a joint a few levels down in the bone hierarchy. When I animate instead the GameObject that has the AnimatorController on it, that works. It's just useless, as we're trying to do character animation.

    My colleague just found that if he moves the AnimatorController from the base object down one level, onto the root bone transform. But none of our existing animations play at that point, and it seems like a bit of a hack.

    Does the above behavior make any sense to anyone? And more to the point, is there any way to make it work short of moving the AnimatorController?
     
  2. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    it was long ago that I did this

    but you know that you have to create a new anim and add properties (bones' rotation) you want to animate

    I made some notes then, don't know if that would help:
    setting keyframe on anim
    setTargets0.cs:
    1. import frame [keyC]
    2. on animation export frame [keyX]
    3. PRESS BUTTON keyframe+ on animation

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class setTargets0 : MonoBehaviour {
    6.  
    7.     //COPY KEYFRAMES
    8.     public KeyCode export = KeyCode.X;
    9.     public KeyCode import = KeyCode.C;
    10.  
    11.     public Transform objRoot;
    12.     int objN;
    13.     public Transform[] recObj;
    14.     int i;
    15.  
    16.     public Vector3[] positions;
    17.     public Quaternion[] rotations;
    18.  
    19.     void Start () {
    20.         objN = objRoot.childCount;
    21.         recObj = new Transform[objN];
    22.         for (i = 0; i < objN; i++) {
    23.             recObj [i] = objRoot.GetChild (i);
    24.         }
    25.     }
    26.    
    27.  
    28.     void Update () {
    29.  
    30.         if(Input.GetKeyDown(import)){
    31.             for (i = 0; i < objN; i++) {
    32.                 positions[i] = recObj [i].position;
    33.                 rotations[i] = recObj [i].rotation;
    34.             }
    35.         }
    36.  
    37.         if(Input.GetKeyDown(export)){
    38.             for (i = 0; i < objN; i++) {
    39.                 recObj [i].position = positions[i];
    40.                 recObj [i].rotation = rotations[i];
    41.             }
    42.         }
    43.     }
    44. }
    45.