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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Importing additional animation curves from an FBX

Discussion in 'Animation' started by jamesong, Jun 21, 2017.

  1. jamesong

    jamesong

    Joined:
    Jun 14, 2017
    Posts:
    19
    How do you get animation data other than transforms and blend shape weights to import from an FBX? You can add other properties in the animation editor for animations created inside Unity, but I can't figure out how to import other properties from an FBX. There's the "curves" foldout in the animation properties, but that only seems to let you add extra animations to the file, not import them. The other curves don't even show up in the raw animation panel.

    This is really basic, so I don't know why I can't find it...
     
    ModLunar likes this.
  2. jamesong

    jamesong

    Joined:
    Jun 14, 2017
    Posts:
    19
    Is this really not possible? This is such a fundamental thing this is making me nervous about using Unity, especially combined with the apparently broken humanoid system that can't import animations accurately...

    I guess I can work around this by creating empty transforms, and putting data on translation, which I can access from script. But ... seriously? I really hope I'm just missing something.
     
  3. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    If you are talking about curves exclusively - You are missing stuff.
    "Other" animation data isn't clear enough to provide a helpful answer. What is 'other'?

    Read documentation and look back through this sub-thread for info. Also humanoid is not broken if you follow the rules and workflow it requires.
    Good luck.
     
  4. jamesong

    jamesong

    Joined:
    Jun 14, 2017
    Posts:
    19
    All other animation: keys on values other than TRS and blend shapes. I want to keyframe material properties, light intensities, properties on my behavior scripts, and anything else. It doesn't matter what the other data is--my FBX has attributes with keyframes on them, and I want to be able to access it. Even if I can't hook it up directly to properties, it's enough if I can access the animation curve from scripts, but the FBX importer seems to just ignore it.

    Telling people to read the documentation isn't very helpful if you can't point people to something they haven't already read. I've already spent plenty of time searching.

    (And humanoid does seem quite broken. See https://forum.unity3d.com/threads/inaccuracies-importing-animation.476768/.)
     
    ModLunar likes this.
  5. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    No this isn't supported in Unity or other engines. It's because FBX doesn't hold that information. This has to be done - in engine.
    No this isn't supported in Unity or other engines. It's because FBX doesn't hold that information. This has to be done - in engine.
    This is vague - but probably no - should probably be done in engine.
    Yes it does
    This is vague - what attributes have keyframes on them? FBX only supports skinning data and bones (mostly) - everything else has to be set up in engine. Same as all other engines.
    This can be accomplished in engine. What exactly do you want to access an animation curve for from a script/property? Would this be to change speed or something? That is done in engine.

    Helpful? - that's how I learned so I'm just passing that helpful nugget along because its obvious you haven't.
    Finding and learning the information is much more valuable than getting it fed to you. Your not learning anything if someone just tells you.
    And - sorry to point this out - it's obvious you haven't read through the documentation or you would know the answers to nearly every question you asked about - including humanoid retargeting - which you are doing wrong -
    The reason the retarget is not working is because unity chan model does not conform (by default) to the humanoid rig, so extra set up (detailed in the documentation) is necessary.

    Go read the docs - and check the live training video about humanoid animation where they go into detail about retargeting unity chan to humanoid, although if you read the documentation - the video isn't needed.
     
  6. jamesong

    jamesong

    Joined:
    Jun 14, 2017
    Posts:
    19
    Of course it does. You can export keyframes on any attribute to an FBX.

    No, that's completely incorrect. You can keyframe anything you want and export it in an FBX. Maybe the software you're using has a poor FBX exporter that can't, but you sure can from Maya. You simply add an attribute on a node, keyframe it and include it in the export. If that wasn't the case then the keyframes wouldn't be there if I reimport them back into Maya, which they are.

    If you're just going to say "RTFM"--which I've done, at length--and refuse to actually point to anything, then you're just being condescending. You don't even seem to understand that FBX can store keyframes for any attribute, which means there's no possibility that you know how to do what I'm describing, so I'd recommend losing the attitude.
     
  7. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    What you are describing is trying to do half the work in Maya - when fbx doesn't transfer that information into the engine. Go ahead - show in engine a fbx import with animated light intensity changes, and material property changes in any game engine??

    Sorry song - I can just tell your asking question before performing research. No biggie - most new users do the same.

    Question - you are using the word attribute so generically - no one can tell what you are actually talking about. Thats why I asked you to clarify. Yes fbx supports simple keyframe transform/rotation/scale into the engine sorry I forgot to mention that - because it's known. But attribute can mean anything that drives a variable. What are you talking about when you say attribute? Changing lights and materials? No not supported.

    Maya, Max, Blender all have basically the same fbx exporters. There might be more 'optional' keyframe attributes available in Maya - but those are special settings only Maya reads. No game engine will read that.
    I'm trying to help - if your not interested - I'll move on to another person having problems who isn't cranky about not being able to retarget humanoid rig correctly because they aren't following the instructions provided. Saulgood-man.

    And you avoided the question - What exactly do you want to access an animation curve for from a script/property? Would this be to change speed or something? That is done in engine.
     
  8. jamesong

    jamesong

    Joined:
    Jun 14, 2017
    Posts:
    19
    An attribute (or property) is simply a value set on an object that can be keyframed. Blend shape weights and transforms are attributes. You can keyframe any attribute on any object in an FBX, as well as create your own attributes and keyframe them.

    You can add animation curves to an imported animation in the "curves" section of animation properties, which allows you to add an AnimationCurve with an arbitrary name. I just want Unity to take any keyframe data in the file that isn't for transforms or blend shapes, and stash it as one of those additional curves. Those curves do try to match up with corresponding Unity properties to figure out what to animate, but even if it doesn't I could simply query the current value from a script and send it off to the right place myself. You can also add curves to an animation with AssetPostprocessor.OnPreprocessAnimation, but that doesn't really help since you can't access the FBX file from there.

    I'm not sure why you need to be rude, but I did answer: "I want to keyframe material properties, light intensities, properties on my behavior scripts, and anything else." There are countless things to animate other than transforms and blend shapes.
     
  9. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Can you give an example of creating your own attribute and keyframing it?

    Fbx capabilities are (afaik) truncated on import into a game engine generally. I've read about custom information being brought in from Maya/Max - however its not available out of the box and that knowledge from what I've seen is held closely to the chest of the teams explaining the high level processes.
    I think you could get the (attribute keyframe) information but it would require a custom importer script to accomplish.
    Elliot Mitchell discussed setting up a custom importer in a Unite talk several years ago.
    I don't know if this is the right one, even though it is old I think the info still applies. He has presented at several events so I can't be sure if this is the right presentation. If not - there is at least one other Unite presentation he was involved with more recently which might have more relevant information.

    If the information isn't available in that video - you might consider contacting him directly, although I don't know him personally so I don't know how approachable he is. He's on twitter [at]Mrt3D.
     
    Last edited: Jun 22, 2017
  10. jamesong

    jamesong

    Joined:
    Jun 14, 2017
    Posts:
    19
    A simple example: a cutscene where the light level changes dynamically, eg. a character turning a light on or off, or light levels changing for dramatic effect, timed to events in the scene. The way I had expected this to work was along these lines:

    - Create a control transform named "Lights" in Maya. (This is just an empty object that serves no purpose other than to hold data, and would have a GameObject equivalent in Unity just like any other transform.)
    - Add a float attribute to the transform, lightIntensity. Keyframe this along with the rest of the scene animation in the same file. Unity doesn't know what this means, but it would import it and stash it for you.
    - In Unity, you already have a "Lights" GameObject, by importing it with the asset (of course you'd have to export it with the asset).
    - Add a behavior script on Lights that does something along these lines:

    void Update()
    {
    light.intensity = this.GetAnimationValue("lightIntensity");
    }

    where GetAnimationValue gives access to the current interpolated value of "extra" animation data on this GameObject, and "light" is just a link to a light.

    I have a pretty good idea of how to get this to work (without writing my own FBX importer):

    - Create a transform named "LightIntensity". This is like "Lights" above, except it'll only hold a single piece of data.
    - Pretend the X transform coordinate is the light level, and keyframe it. (I'd do this in a more elegant way in practice, but that's what would end up in the FBX.)
    - In Unity, you now have an empty transform that animates based on how much light there should be. It's just a transform bobbing back and forth with nothing inside it.
    - Now, the behavior script looks like this (again simplifying):

    void Update()
    {
    light.intensity = this.transform.localPosition.x;
    }

    It's a hack, but I think it should work well enough. I'm just surprised at needing a hack--it feels like something everybody must be working around in one awkward way or another.
     
  11. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Makes sense - this is called wire parameters in Max. Adjust one physical thing - the position of a spline or dummy object to effect the parameter of something else. Very same input as animators use a lot for facial control rigs which drive position rotation of bones rigged to a character.

    But still - I don't know/think this info translates into the engine without customization. Hope you figure it out though. With your code knowledge - anything is possible. I'm just a luddite animator. :confused:

    Are you set on solving this because you are more comfortable working in Maya than Unity? I only ask because this is a pretty simple set up in Unity with either a tween tool, mecanim, and using scripts to 'wire' it up, or using one of the numerous visual scripting tools - I've done similar set ups with Playmaker on several occasions.
     
  12. jamesong

    jamesong

    Joined:
    Jun 14, 2017
    Posts:
    19
    If I'm creating an animation in Maya, I want to create the entire animation in Maya. I don't want to create a scene in Maya with only character movements, then set up lighting animations inside Unity to match the imported animation. Doing it all in the same place means I can preview everything together, and everything gets timed together. If part of a scene is retimed, the light animation will go along with it and I don't have to go back and re-time it in Unity to match the changed animation. All keyframe animation can be authored in the same place with the same tools, and not split between Unity and Maya just because of importer limitations.
     
  13. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I'm not talking about animating in Unity - I'm suggesting setting up parameter changes in engine. A lighting change can be made to 'happen' in Unity without having to animate it. It can be changed based on an event, trigger, bool - etc etc. Same as you are wanting it to happen in Maya - but without it having to be animated.
     
  14. campo_pete

    campo_pete

    Joined:
    Apr 14, 2017
    Posts:
    1
    I just found AssetPostprocessor.OnPostprocessGameObjectWithAnimatedUserProperties, which is lacking all documentation and only mentioned here https://unity3d.com/unity/beta/unity2017.2.0b5, but coupled with an import script should be able to do what you want (bind the custom curves you export in the fbx to attributes on components).

    There is also this https://docs.unity3d.com/ScriptReference/ModelImporter-importAnimatedCustomProperties.html, which also seems to be lacking all documentation, but if enabled, is supposed to automatically hook up to parameters on an animation controller.

    Hope this helps someone.
     
    ModLunar and theANMATOR2b like this.
  15. Bezzy

    Bezzy

    Joined:
    Apr 1, 2009
    Posts:
    75
    It helped me, pete!
     
    ModLunar likes this.
  16. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    372