Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Non-bone curves in FBX-based animation clips in Timeline track

Discussion in 'Timeline' started by RobO_HB, Jan 11, 2022.

  1. RobO_HB

    RobO_HB

    Joined:
    Sep 16, 2013
    Posts:
    16
    Hello, I have a situation where I have animation clips coming from FBXes driving characters in a Timeline. In these FBXes, along with the curves that drive bones, there are additional animation curves that I would like to use to drive other values on a component on the character.

    Most of the examples I've seen on this forum and elsewhere for doing something similar (for example, driving blendshapes via a Timeline track) involve actually recording the change in the blendshape directly in Timeline. That workflow will not work for our team - we need some way to have the curves in question come in via an FBX and then bind them to the values we care about on the character.

    The only way I have come up with is to pre-process the FBXes to extract the curves into some other asset file, and then evaluate those curves in lockstep with the animation that is being evaluated. This approach should work, but also seems like a pretty convoluted way to evaluate an animation curve in lockstep with a Timeline track - pulling curve data out of the format that it is being imported in, into another format, and then writing code to evaluate those curves in parallel to Timeline when (it seems like) that's exactly what Timeline is built to do to begin with.

    Is there any way to access/evaluate curves that do not correspond to skeletal bones that are part of an animation track in timeline, and/or to bind those curves to some receiver object?
     
  2. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    I am not an FBX expert, but animation clip files can certainly do this. You can add multiple properties to animate. Bones specify a relative path to a game object inside the object bound to the track then animate Transform properties. But you can add properties of any component you like. E.g. I create a facial expression component (in C#) and animate those properties instead of adjusting blendshapes directly. I also have a Head Turn component that tracks an object - I can animate the weight of the head turn between two objects, so the character turns the head from looking at one target to another.

    To do that in an animation clip, I either create a blank animation clip file, drag into a timeline, then hit the record button and start changing properties of the game object bound to in that track, or I double click the animation clip file and use Add Property directly (I find this a bit harder myself for complex objects).

    Generic vs Humanoid animation clips are the same. Generic does bone Transform manipulation, Humanoid animates properties of the Animator component (muscle strengths that go between -1 and +1). Both can be in a FBX file, so I am pretty confident you can animate more than bones in a FBX file as well. (That is, Humanoid clips do not do bone transformations and can live in FBX files.)

    If you want to extract an animation clip from a FBX file, then easiest way I know is to select the clip and click "duplicate". That makes a copy outside the FBX file. You may not need this, but it was not obvious to me initially.

    The question that came to my mind was what is creating the FBX files you import. Can it create animation clips that are not bone animations?
     
  3. RobO_HB

    RobO_HB

    Joined:
    Sep 16, 2013
    Posts:
    16
    The FBX is coming from MotionBuilder, which can include curves in the FBX named whatever you'd like.

    The challenge I'm running into is how to bind that to the correct component at runtime, since our animations are in individual FBXes, separate from the FBX containing the character model. If I create an anim myself, I can select the component and attribute and animate it. Upon saving this, in the .anim file (in a text editor) I can see the curve, the name of the attribute, and a script reference (fileID, guid, type) to the component in question.

    Since the animation is coming in as an FBX, however, and then bound to the character at runtime, I'm not sure how to let Unity know about the correct binding. Bone animation carries over just fine, assuming you have your avatar and avatar mask set up, etc. But I haven't been able to find any documentation specifying any curve naming convention to have Unity "figure out" that a given curve is supposed to affect component X, attribute Y. Nor have I found any API allowing me to set up that binding at runtime.

    The closest I've found is this: https://docs.unity3d.com/ScriptRefe...cessGameObjectWithAnimatedUserProperties.html

    However, that's for import time, at which point we don't have *the* gameobject that the animation will eventually be bound to (again, said game object is not stored in the same FBX that the animation is stored in). So I'm at a bit of a loss for how to grab those animated user properties *at runtime* and bind them to the correct properties on the character object.
     
  4. akent99

    akent99

    Joined:
    Jan 14, 2018
    Posts:
    588
    Sorry, that is the end of my knowledge too. I will only add that I use animation clips (from FBX or as .anim files) in Cinemachine timelines all the time, where the binding of a game object to a track is held in the *scene* (not the Timeline asset). So I think its common for animations not to be bound to a game object - i think they are instead bound to components and properties of those components. But no idea of the naming conventions used. Oh, and I did notice different styles of names for muscles (humanoid clips), so there may be a difference between component properties and dynamic (?) attributes that a component can expose - that is, the muscles are not properties of the Animator component that I can see, but an animation clip can animate them - so watch out for those as well....

    I played a little with the BVH format for animation clips (supported by Blender and another app I was using). It was another text format. I ended up using a command line Blender invocation to convert the BVH files into FBX files. Not sure any use, but there might be documentation on BVH around if you cannot find the Unity answer directly... maybe!!! Good luck!