Search Unity

  1. How has 2019.2 and the beta been for you so far? Give us feedback in this thread.
    Dismiss Notice
  2. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

New Animationclip property names

Discussion in '5.3 Beta' started by SinisterMephisto, Nov 11, 2015.

  1. SinisterMephisto

    SinisterMephisto

    Joined:
    Feb 18, 2011
    Posts:
    176
    Hi is there any chance we can see the new animation property names?

    So far I have
    Code (CSharp):
    1. localEulerAnglesRaw.x
    2. m_LocalRotation.w
    previously m_LocalRotation used to be localRotation
     
  2. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    I'd like to know the euler property names too please. localEulerAnglesRaw.x didn't work for me.

    EDIT: To add a little more information. I'm trying to use clip.SetCurve(...) with the new beta euler curve property for rotation.
     
    Last edited: Nov 16, 2015
  3. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    282
    TL;DR: In 5.3 and onwards, use AnimationClip.SetCurve as much as possible

    AnimationClip.SetCurve:
    • m_LocalRotation / localRotation, Quaternion
    • m_LocalEuler/ localEuler, Vector (5.3 and onwards)
    AnimationUtility.SetEditorCurve:
    • localEulerAngles / m_LocalEulerAngles Euler keys, Quaternion results
    • localEulerAnglesBaked / m_LocalEulerAnglesBaked Euler keys, Quaternion results that try to look like Euler
    • localEulerAnglesRaw / m_LocalEulerAnglesRaw Euler keys, Euler results (5.3 and onwards)
    Don't use localRotation with AnimationUtility.SetEditorCurve, use AnimationClip.SetCurve instead
    • localRotation / m_LocalRotation Quaternion keys, Quaternion results, used in conjunction with localEulerAngles, localEulerAnglesBaked.

    Long version

    I'll give the long explanation here for posterity's sake.

    For transform properties, both local<Rotation/Position/Scale> and m_Local<Rotation/Position/Scale> are supported, and you should probably support both if you read/write to those curves.


    For transform bindings (local<Rotation/Position/Scale> / m_Local<Rotation/Position/Scale>), there are two types of bindings; Vector and Quaternion.

    Quaternions are split into 4 float curves: x,y,z,w.
    Vectors are split into 3 float curves: x,y,z,w.

    Position and Scale are Vectors, so they have x,y and z. Rotation is a Quaternion, so it x,y,z and w.

    Those curves are named m_Local<Rotation/Position/Scale> because they map directly to serialized properties of the Transform that have those actual names. local<Rotation/Position/Scale> is just an alias

    If you use AnimationClip.SetCurve, you can use those names, plus the appropriate suffixes(x,y,z,w) to create curves in your clip.


    In 5.3, we added a new property; m_LocalEuler / localEuler. I follows the naming convention that the other curves use, but it doesn't map directly to a serialized property.

    m_LocalEuler is a Vector3 (x,y,z), and you can also use it with AnimationClip.SetCurve to create an EulerCurve that is equivalent to animating transform.localEulerAngles.

    Before 5.3, if you wanted to add Euler keyframes to an AnimationClip, you had to use AnimationUtility.SetEditorCurve with special bindings. In 5.3, you should be able to do everything directly in AnimationClip.SetCurve.

    We strongly suggest you directly use AnimationClip.SetCurve in 5.3. It should greatly simplify any existing code, minimize chances that changes we do for the AnimationWindow breaks your tools, and give better results.

    However, here's a rundown of how AnimationUtility.SetEditorCurve works:

    Since editing quaternion curves is not really interesting, in the AnimationWindow we use AnimationUtility.SetEditorCurve to set special bindings that simplify working with rotation curves. Those bindings never make it to runtime, and are only used to simplify our work in the AnimationWindow.

    The following rotation properties are available through AnimationUtility.SetEditorCurve:
    • localEulerAngles (x,y,z) (unchanged from 5.2)
      Used by the Quaternion interpolation mode. Euler keyframes, translates to a quaternion curve. Affects m_LocalRotation

    • localEulerAnglesBaked(x,y,z) (unchanged from 5.2)
      Used by the Euler Angles(Quaternion Approximation) mode. Euler keyframes, translates to a baked quaternion curve that approximates euler interpolation between user-supplied keyframes. Affects m_LocalRotation

    • localEulerAnglesRaw(x,y,z) (new in 5.3)
      Used by the Euler Angles interpolation mode. Euler keyframes, euler curve. This is evaluated as an euler curve up until it has to be written into the rotation of the object. Affects m_LocalEuler
    Those three bindings also have a m_ version that you will probably want to support

    Beware: You can't mix and match these types. If you want to write to one of these, you need to set all the others to null. Doing otherwise will give you errors.

    This means that you can't set localEulerAngles.y if you have any curve on localEulerAnglesRaw. You need to clear all the localEulerAnglesRaw first.

    Finally, there is also one quaternion binding that you can use, but we strongly suggest that you directly use AnimationClip.SetCurve for this one, because it's used in conjunction with the three euler bindings, and trying to manage this without access to the underlying code will be a nightmare. Use AnimationClip.SetCurve instead.
    • localRotation (or m_LocalRotation, both are supported)
      Quaternion curves, quaternion keyframes. Affects m_LocalRotation.(unchanged from 5.2)

    Changing any of those editor curves (through AnimationUtility.SetEditorCurve) will cause changes in the underlying curves to which they map, and changing the underlying curves (through AnimationClip.SetCurve) will cause changes to those curves.
     
    Last edited: Nov 16, 2015
    karl_jones and CWolf like this.
  4. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    That is a fantastic answer. I can't ask for anything else - thank you very much @DavidGeoffroy.
     
    holliebuckets likes this.
  5. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    282
    Glad I could help. Feel free to reply here if you get issues with this. We don't have many users who use this, and since it's mostly used internally, it's really underdocumented.
     
  6. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    I hate to say it but I am actually getting issues. To give some context, I'm writing a Collada importer in managed c# code. I'm dealing with animation curves from the import.

    After processing my curves I do the final...

    Code (CSharp):
    1. clip.SetCurve(key, typeof(Transform), "localEuler.x", xRotCurveFinal);
    2. clip.SetCurve(key, typeof(Transform), "localEuler.y", yRotCurveFinal);
    3. clip.SetCurve(key, typeof(Transform), "localEuler.z", zRotCurveFinal);
    When checking my animation, it doesn't seem valid (it doesn't run). I do see the curve in the animation window when debugging in Unity Editor though but the animation won't play.

    If I use the following code...
    Code (CSharp):
    1. clip.SetCurve(key, typeof(Transform), "localRotation.x", xRotCurveFinal);
    2. clip.SetCurve(key, typeof(Transform), "localRotation.y", yRotCurveFinal);
    3. clip.SetCurve(key, typeof(Transform), "localRotation.z", zRotCurveFinal);
    4. clip.SetCurve(key, typeof(Transform), "localRotation.w", wRotCurveFinal);
    the animation works (but at this point I'm having my own code issues so I'd like to use 'localEuler' for rotation as it would make my life a lot easier).

    Any suggestions? Am I doing something wrong?

    EDIT: Just to confirm, for the first code example I'm using Euler curves and when I try the second code block I convert the Euler into Quaternions and build Quaternion curves so, at least from my understanding, what I'm doing should work with 'localEuler'.

    EDIT2: I only ever use AnimationClip.SetCurve as the mod tool I'm developing is runtime / UnityEngine only (not Editor time).
     
  7. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    Also a change from Unity 5.2.2 I noticed is that the curves now seem to show in the Animation window upside down. The curve used to be positive and now the same curve is negative values. Has this been seen before?
     
  8. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    282
    When checking my animation, it doesn't seem valid (it doesn't run). I do see the curve in the animation window when debugging in Unity Editor though but the animation won't play.
    Hmm... it's probably broken in Legacy. I'll see what I can do about a patch for that. We try to modify Legacy as little as possible (because it's going to be deprecated soon™)
    It should work in Editor for humanoid and generic though. (Not that this helps you much)

    An alternative to Legacy I suggested to someone working at BigCompanyX is:
    You could offload this to a server farm (Amazon, Azure, your own), send the collada file, run the editor in command line on the server, and return an assetBundle. But unless you plan to sell this feature, that's not viable.

    Also a change from Unity 5.2.2 I noticed is that the curves now seem to show in the Animation window upside down. The curve used to be positive and now the same curve is negative values. Has this been seen before?

    The evaluation of Quaternion to euler has changed a bit in the alpha/beta. Normally, the values should be equivalent (-30 vs 330), but it might be a bug. If it's a problem, please file a bug with a small repro case, paste it here and I'll check it out.

    I'll check it right away, because I'd rather iron out those bugs early on.
     
    CWolf likes this.
  9. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    I am using Legacy so it's possible if you say it may be a problem there. Any work to fixing it would be great and much appreciated.

    We would love to eventually move over to non-Legacy / Mecanim but the runtime / UnityEngine time support for end-to-end script-only Mecanim wasn't where we needed it last time we looked. We need full runtime script access to creating state machines, re-targeting and avatar creation (among other things). This would allow game modders to set up their own animation workflow / transitions using our dedicated, and bundled, mod tool.

    The suggestion you gave about offloading the model import to a server farm is an interesting one but one I'm not sure would work well for our use case (and since we don't plan to charge for mod support / tools it would become cost prohibitive).

    If the animation graph isn't technically wrong I wouldn't call it a problem on my end. We only use the unity Animation window to confirm the animation is in there when debugging the importer. It tends to show the curves differently to Maya anyway so it may be something we just get used to. I can try to raise a case against it anyway just in case if you need it to investigate. Trying to make a small project might prove a little tricky due to the model import code being substantial in size, as you can imagine.
     
    Last edited: Nov 17, 2015
  10. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,156
    A lot of this should be possible as of 5.2 via the Playables API (and runtime avatar creation has been possible for a while, via UnityEngine.AvatarBuilder). You should check it out! :)
     
    CWolf likes this.
  11. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    Really? That sounds exciting! Thanks for the heads up, @superpig :).
     
  12. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    When I last checked about avatar creation it was Editor only so will look into that as well.
     
  13. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    282
    The fix for Eulers in Legacy is done.
    It'll get patched in soon™
     
    CWolf likes this.
  14. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    That was awesomely quick. Thank you so much =).