Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Animation Curves on non-external animations

Discussion in 'Animation' started by VergilUa, Apr 16, 2018.

  1. VergilUa

    VergilUa

    Joined:
    Dec 22, 2014
    Posts:
    621
    Hi guys. I'm wondering, is there a way to set an custom data animation curve at native animation?
    The one that isn't imported via external files (.anim files).

    In a same way as:
    https://docs.unity3d.com/Manual/AnimationCurvesOnImportedClips.html

    I can't find anything relevant on the topic.
    I cannot use default imported ones, because I need to change some properties on them.
    But at the same time I cannot add animation curves for my footsteps blend tree.

    I've tried first adding animation curves to the .fbx import settings, and then duplicating them, but the curves doesn't transfer that way. Maybe I'm doing something wrong.

    Any suggestions would be appreciated.
     
    Last edited: Apr 16, 2018
  2. VergilUa

    VergilUa

    Joined:
    Dec 22, 2014
    Posts:
    621
    After some digging into sources and reflection, I've found out that for some reason m_ClipInfo of AnimationClipEditor is never actually assigned inside of it. That's why CurveGUI() is never drawn for a separate .anim files.

    This is either by design, or a bug. But it definately feels like some one was just too lazy to make another .Get() for an actual serializedObject inside AnimationClipInfoProperties.

    Some official info would be great.
    I don't really know who's writing UI for AnimationClip component.
    Maybe @Mecanim-Dev can help solving this one.
     
    Last edited: Apr 16, 2018
  3. VergilUa

    VergilUa

    Joined:
    Dec 22, 2014
    Posts:
    621
    Figures out Unity stores two different types of animation clips.
    The one that's imported from model is called ModelImporterClipAnimation, and the actual created duplicate of that is AnimationClip, which doesn't even contain curves data property.

    AnimationClipInfoProperties are used specificly for the ModelImporterClipAnimation, and not the AnimationClip. So using an AnimatorClipEditor for those purposes are no go unfortunately.

    Best solution I guess would be either somehow create a data set / ScriptableObject that stores that information (curves, events etc) from ModelImporterClipAnimation when it's duplicated into AnimationClip and then also apply that.

    Unfortunatelly I'll be left with the same problem again, impossibility to actually edit curves. Maybe there's a different option. I guess I need to investigate how the actual curves are applied to the AnimationClip itself, when ModelImporterClipAnimation is used.

    Maybe there's an asset already that does the same, of which I'm not aware of?

    (Forum is ded though, why I keep posting this? LUL)
     
  4. VergilUa

    VergilUa

    Joined:
    Dec 22, 2014
    Posts:
    621
    Seems like this thread is going to be my blog. Since I've started progress posting, why not continue?

    I haven't found any solution, so I've decided to hack my own one.

    Small progress update:
    I've ended up writing additional ScriptableObject to store curve data, and AnimationClip itself.
    Also managed to salvage up code from AnimationClipEditor and attach it to my own SO's editor.
    Prettified it a bit, overall looking good.

    ScriptableObject's Editor:
    upload_2018-4-18_15-15-28.png

    Only thing left is to write an extension component for an Animator which feeds it actual curve parameters.
    Another bottleneck - additional curves handled on the native side of the Animator, which makes a trivial task into a bit of hacking again. This also means - no API for actually setting curves for native side. This would've been a blessing, since it would've also handled curve blending and increased performance (by decreasing operations done by additional component).

    Also, there's no way to extend actual Animator class, since it's sealed. So Animator.IsParameterControlledByCurve cannot be overriden (which is a shame, but not really a big loss).

    Another thing is that these custom curves have to be blended manually, which is maybe a problem too.

    I'll post conclusion later about Pro's and Con's of this solution (which is taken me more time than I expected from the trivial task).
     
    Last edited: Apr 18, 2018
  5. VergilUa

    VergilUa

    Joined:
    Dec 22, 2014
    Posts:
    621
    Conclusion and overmidnight rambling:

    So, in the end I've managed to get up and running Animator Extender component, which feeds that curve data into the Animator's parameters. This solved my issues with events & blend-trees, since I don't need events anymore.

    Figures out you can pull AnimatorClipInfo from current played state. Which contains "weight" for the clip. You can use that value in junction with curve's evaluated one, and apply it all together as a parameter. This works out for the blend-trees, you just need to sum them up before applying.


    Such a small and simple thing took me almost a week to research and implement. I don't think that this is actually "indie" friendly. Really.

    And to be honest - it should be available from the package.

    To reproduce the editor I had to modify actual UnityEditor.dll.
    (You can always go without it, and make your own. But preview is too nice to not being able to use it, so is TimeRulers etc.)

    Seriosly, EVERYTHING is internal!
    AvatarPreview, TimeArea, ZoomableArea and so on. These classes shouldn't be internal marked. Just doesn't makes sense to me. Sure, you can always ctrl+c -> ctrl+v from UnityCs reference and create a duplicates of the same classes. But why??? Really?

    If you don't expose library, it's just becomes reflection hell, which hurts performance of the editor a LOT.

    For the reason above - this solution is actually useless for anyone else.
    And for the same reason I won't share code, since I don't think it'll be usefull anyhow, or legal.

    Worst part - Animator is not really an extendable class. It's almost completely resides on the native side with the lack of any exposed API to it. Sending curves to the native side would've been a blessing, since it would've cut overhead of my extension to almost to zero.

    Overall:

    Pro's:
    + No events required anymore, anything can be replaced by custom curves / parameters
    + Animation driven parameters.
    + Ability to create instances of AnimationClips,
    + Customizable editor GUI
    + Extendable for project's needs

    Con's:
    - Reflection heavy, or copy paste heavy or library modification skills required.
    - Time cost. Journey to reliable blend-tree footsteps costs too bloody much.
    - Small performance overhead from additional runtime component. (Still, better than AnimationEvents, ugh)

    TL;DR for Unity Team:
    Just put the "curves" property into the actual AnimationClip in the future releases. (or at some point in time) and link it to the native side of Animator. I'm not asking for a proper AnimatorClipEditor.

    P.s:
    If anyone in the future have same issue as I did - my suggestion - go with the simplest solution you can come up with. Just dump the Animator/Clips and use some sort faking of the footsteps.

    I have done it just because I wanted them to be more in sync with the animation.
     
    Last edited: Apr 19, 2018
    petey likes this.