Search Unity

Question How do you read an animation curve from an imported clip?

Discussion in 'Animation' started by spylefkaditis, Jul 7, 2020.

  1. spylefkaditis

    spylefkaditis

    Joined:
    Jul 3, 2016
    Posts:
    22
    Is the only way to read the value of an animation curve created in an imported animation clip to create a parameter of the same name in the Animator? Again to clarify I'm not talking about curves created in the Animation window.

    The only official documentation I found is this
    https://docs.unity3d.com/560/Documentation/Manual/AnimationCurvesOnImportedClips.html

    There doesn't seem to be any reference to this in the new documentation.

     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    It can also be done with Animation Jobs. I've included some jobs to do that in the Animancer Lite v5.0 Beta (in the Utilities folder), but I don't know how to use Animation Jobs with a regular Animator Controller, only when using the Playables API.

    Before that, I made an ExposedCurve scriptable object which just gets a specific curve from an animation in the editor and serializes it separately so that you can access it there. It was not particularly convenient, but you can still download it from the Animancer Documentation if you want.
     
  3. spylefkaditis

    spylefkaditis

    Joined:
    Jul 3, 2016
    Posts:
    22
    Hey @Kybernetik .You seem to know alot about animations haha. You're always answering questions on here. I appreciate it.

    In the end I created my own animation curves on my script to read the values, but that means that I had to manually set the clip length myself.

    The whole point of this was so that I can use the curves I created representing Y and Z to move my characters position in line with the animation, when I play a climb up animation (from hanging).

    Can you suggest a better way to do this? Is this an acceptable approach or am I doing something stupid?
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    It sounds like you just want to use root motion. Even if you only use it for that animation and script everything else, you can turn it on and off whenever you want.
     
  5. spylefkaditis

    spylefkaditis

    Joined:
    Jul 3, 2016
    Posts:
    22
    Thanks for getting back to me. If I don't have a root motion animation would my approach be reasonable?
     
  6. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Your approach is essentially just a manual hacky way of implementing root motion. There's no reason why it wouldn't work, it's just that it should be far easier to have the animation move the character directly instead of trying to eyeball it with your own curves.

    Are you sure that animation doesn't have root motion? I'm pretty sure the red light in your screenshot means it does, so you probably just need to disable the Bake Into Pose toggle for the Root Transform Position (both Y and XZ).
     
  7. spylefkaditis

    spylefkaditis

    Joined:
    Jul 3, 2016
    Posts:
    22
    It does but I was having issues with it working so I just attributed it to me doing something wrong.

    The issue I'm having is that when the climbing animation begins, it starts from the root of the collider (where the 3 dots are) not from where the characters hands are, meaning he doesn't finish playing the animation where he should. Should I shift the collider up before triggering the climb up animation or should I use match target or something?

     
  8. spylefkaditis

    spylefkaditis

    Joined:
    Jul 3, 2016
    Posts:
    22
    So I shifted his position up before playing the animation and it looks fine...is that right? I come from a web dev background and I always try to avoid these magic numbers.
     
  9. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Try changing from Center of Mass to the other option and I think there's a Y offset as well which might help. I haven't really done much with root motion so I always just end up trying different settings until something works.

    I agree that it's good to avoid magic numbers, but sometimes it's better to just find something that works so you can move on.
     
  10. spylefkaditis

    spylefkaditis

    Joined:
    Jul 3, 2016
    Posts:
    22
    I appreciate the help man. I tried playing around with those settings and nothing seemed to make a difference. I'm going to try and see if changing the collider height will make a difference. At least he's climbing now. Thanks for your help again man.

    Just out of curiosity, when you say you haven't done much with root motion, how do you go about animating your characters? Have you done a climbing action before?
     
  11. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I mostly just script all my movements and as a programmer I tend to work on games with less of a requirement for high quality art and animations. I haven't tried to implement climbing before.
     
  12. spylefkaditis

    spylefkaditis

    Joined:
    Jul 3, 2016
    Posts:
    22
    Fair enough. Thanks for your help again.