Search Unity

Stepped Animation Keyframes

Discussion in 'Animation' started by Cactus_on_Fire, Jan 29, 2015.

  1. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Hello all.

    I'm trying to make an animation look like stop motion. For this, I need the keyframes to have stepped tangents.
    I set all of them to constant in the animation graph editor but it acts like this.



    Also the original FBX animation is keyed every 4 frames, but Unity adds all the keyframes in between automatically.

    How can this be solved ?
     
  2. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
  3. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    The keyframes should be set to stepped in the original animation software before importing into Unity.

    Or here is another solution - again done in the animation package not Unity.

    http://forum.unity3d.com/threads/no-interpolation-with-animation.274974/#post-1842202

    I provided a rough video example in one of the posts.


    Are you sure about this?
    Do you mean the original animation is keyed every 4 frames in your animation software but when you export and bring it into Unity there is a keyframe on every frame?
    Unity doesn't do this as far as I know - the fbx exporter settings might be set up incorrectly on your export - did you bake the animation? If you baked the animation - the fbx export created every keyframe on every frame - not Unity.
    May try to edit your fbx export settings to solve this.
     
  4. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Yep. The maya animation is stepped and looks perfectly like stop motion.
    However Unity keyframes look like this.



    The FBX from Maya is keyed every 4 frames without baking every frame, I reimported it back to Maya to confirm it.
     
  5. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Feels like it has an easy solution. Is there no way to achieve this ?
     
  6. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
  7. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Sorry to post again with the same solution - but have you attempted the process I suggested in the post I linked?
    I crudely tested stepped keys coming from Max into Unity and it worked as intended but I understand the way it 'should' work with stepped keys isn't working coming from Maya.

    You may want to attempt this as test just to see if it works as a workaround.
    In animation package set keys linearly 1 key at frame 1 where the object doesn't move, copy the 1 key to frame whatever (29) so the object doesn't move from frames 1-29 then move the object to the new position on frame 30.
    keep new position linear key from frame 30 to 40 so object doesn't move, move object at frame 41.
    Manual stop-motion.


    This mimics stop motion by keeping the object/character motionless for a specified duration 1-29 frames, then instantly changes the position/rotation of the object in one frame (frame 30), then keeps the object/character motionless from frame 30-40, then moves the object at frame 41.

    I did this before on a pre-rendered animation a couple 5+ years ago. I haven't attempted it going into Unity, until now.

    Here is a quick rough test from Unity.


    Please update with your findings. I'm sure there's a way to accomplish this in Maya, but without that solution the above process does work.
     
  8. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Yep, I exported the same animation from both Maya and Max in FBX format. The thing is, Unity doesn't like custom curves and always produces a wobbly curve tangent no matter what. The constant key option should produce a clearcut jump in the keyframes, but for some reason it produces a result like the image in the first post.

    The example in your post is also acting wobbly between keyframes. Rather than just stepping key to key, it uses the auto smoothed curves.
     
    Last edited: Feb 3, 2015
  9. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I'm running free so I didn't check the curves. I don't want to torture myself by seeing something I can't play with! :)
    That was a quick test while on break at work so I don't have the file on hand.

    I'm not doubting your knowledge or findings but how can there be a smoothed curve between two keys that have 0 frames between them?
    There isn't room for a curve - it should fake a stepped motion.

    Does Maya have Euler animation controllers? I wonder if editing from Quaternion to Euler could change the export.
    Max also has a outdated TCB animation controller. I wouldn't suggest using that animation controller, but I wonder if it has any effect on the export/import. Will perform a couple more tests tomorrow when I have some time.

    It'd be great to come up with a solution to use and spread to others who have attempted the same effect.
     
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Why not simply play the animation normally and set the animation speed to 1 for a a couple of frames and 0 for a couple of frames and repeat that? this has the effect of stop motion with a normal animation technique. No need to bother with specifics in unity or the 3d package, it's just business as usual, or just hop through the animation by adjusting the time manually for the animation (if legacy, it's trivial).

    In any case, code can solve this via the manner you play things back.
     
  11. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675

    Well here's the thing : There is just 1 frame between the keys, and it shouldn't act like there is more frames in here. But Unity's actual playing framerate is higher than the frame count of the animation. So it plays a few more frames than the animation keys. And since those keys have curvy tangents, it produces wobbly animations.




    I also exported the FBX from quaternion, euler and baked euler. No change. I open the same FBX in Max and it works just like stop motion, so the FBX animation curves have no problems. It's Unity that screws things up.

    I need to set the tangents constant so they have step like curves. like the bottom example. But setting them to 'constant' produces a result like the original post.



    How can this be solved with a script ?
     
    Last edited: Feb 3, 2015
    theANMATOR2b likes this.
  12. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Cool hippocoder!
    That elusive mysterious solution to all the problems. Code.
    Probably the best solution is hippocoders suggestion. But as a artist there should be a solution that doesn't require code I think.

    Just a follow up - checking the curves from the example I posted yesterday I see no visual discrepancy in the bending cylinder object in the game/scene though there is visible 'hitch' on the curve - between the keys. But from the example shown the 'hitch' on the curve doesn't effect the animation of the object when viewed .

    upload_2015-2-3_9-59-45.png


    The example does in fact show a wobble on the curve but it isn't visible on the object in the scene because in the example there aren't any blank frames between the transition keys.

    Could copying the first key (motionless) to the frame between the two keys overcome the wobble you are experiencing?
     
  13. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    nope. Unfortunately it produces a similar result to the original post image where the curves go mental.
     
  14. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    One other random idea - since I'm not experiencing the problem as you are I can't trouble shoot - I wonder if changing the animation framerate in Maya/Max to 60 fps, and then setting side by side keys without any space would result in a different outcome?
     
  15. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    Nope. Tried that, no luck.
     
  16. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Looks like @hippocoder has the best answer. Would like a visual update if you choose a solution he suggested to see how the process turns out!
     
  17. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    How can I set the animation speed like that ? I found a code that can set the animation speed overall, but not like setting it frame by frame.
     
    theANMATOR2b likes this.
  18. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Sorry Cactus - Im allergic to code. :)
     
  19. tealm

    tealm

    Joined:
    Feb 4, 2014
    Posts:
    108
    Old thread - but I'm dropping a comment here incase my solution will be useful to others.
    It's a workaround, but works great for me:

    1. Duplicate your animation clip imported from your rig@animname.fbx
    2. Rename duplicated animation clip to animname_stepped or whatever you want
    3. Open Animation window - select your desired joint(s), and select all of the keys you want to convert and RightClick -> Both Tangents -> Constant
    4. Drag and drop your duplicate stepped AnimationClip version into your AnimationController and place your transitions as needed.

    For larger projects you should probably automate this process - in that case good information here: http://docs.unity3d.com/ScriptReference/AssetPostprocessor.OnPostprocessModel.html
    and here: http://answers.unity3d.com/questions/187907/how-to-add-keyframes-on-imported-read-only-animati.html

    *EDIT* this is working from unity default fbx export settings (Resample as Euler Interpolation selected, Bake Animation checked and Resample All unchecked) I also leave Resample curves unchecked and Anim compression off in the Unity settings for the desired rig@clip (fbx) animation (though im not sure if this is needed).
     
    theANMATOR2b likes this.
  20. Cactus_on_Fire

    Cactus_on_Fire

    Joined:
    Aug 12, 2014
    Posts:
    675
    I tried the constant tangents but then it looks like the first image I posted above. So it appears like it's stepped but since the framerate doesn't match the animation keys, you see small quick jumps from one frame to another, which ruins the stop motion effect.

    I've gone through a whole other way and used a rendertexture camera that takes shots at a given interval so it looks stop motion :)
     
    theANMATOR2b likes this.
  21. NIOS

    NIOS

    Joined:
    Jul 12, 2014
    Posts:
    59
    I'm having the same problem using two consecutive keyframes in Maya for camera changes. Nothing works, even at 120 frames a second for the animation clip (no one should have to do that), Unity still adds its own curves inbetween the keyframes. There really ought to be a solution to this. Im sorry you had to find a new solution Cactus... I was looking forward to someone posting a solution for animations (yeah I know camera shots are easy in code, I'm lazy)
     
  22. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Unity should *definitely* have a built-in way to handle this stop-motion effect -- non-destructively -- for both 2d AND 3d animations.
     
  23. tealm

    tealm

    Joined:
    Feb 4, 2014
    Posts:
    108
    Did you try the method i suggested? Its working fine for me. (Used for offsetting uvs on my rigs for swapping textures, ie: open eyes into closed eyes on image planes.)
     
    theANMATOR2b likes this.
  24. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    It's a creative workaround it seems, but it's still really painful to have to duplicate animation for every asset in a game.

    I personally would prefer a way to select a clip or group of clips and automatically convert the curves on certain areas that are, say, marked with an animation event or some such, so that this could be done at runtime.

    @hippocoder mentioned something similar to this in an earlier post here, but I wasn't understanding how one might affect the playback speed at runtime at specific parts of an animation without having to duplicate and mangle the animation curves for every animation manually. Juggling duplicate animation references is just tedious imo.

    If I could understand how to modify playback to stop on a specific frame for a few frames using, say, 2d sprite parts, I'd be set. He mentioned using the Legacy system to do this, but I'm not sure how one might go about that.

    Any other ideas?
     
    theANMATOR2b likes this.
  25. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    This has been an issue since forever when importing animations from FBX files, because Unity resamples animation curves by default, which destroys stepped tangents, and basically bakes the curve.

    This was done for historic reasons, one of which was the fact that FBX uses Euler format, and Unity used Quaternion format. To convert the curve from Euler to Quaternion, Unity needs to sample the Euler curve every frame, and create a corresponding Quaternion keyframe. There is no way to retrieve stepped tangents during this process.

    One way to minimize this issue is to increase the framerate of the animation, but that's just a hack.

    Since Unity 5.3, in Generic animations, you can unselect the "Resample Curves" checkbox, and your stepped tangents should be kept*.

    *as long as you are not using unity-unsupported FBX features like pre- and post- rotations on your joints. If you are using those, the FBX sdk will automatically resample those curves when importing, and we will not be able to keep your stepped tangents.

    This will also import all your rotations as Euler rotations (necessary to avoid resampling), so they will be kept as close as possible to the original FBX file.
     
    theANMATOR2b likes this.
  26. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    @DavidGeoffroy
    The problem is -- I'm animating in Unity natively -- or, in other words, I'm creating my stepped animations INSIDE unity itself using a number of sprite assets in the same animation as a single character.

    I simply want a way to set a group of frames to have a specific number of steps between each frame that I can specify, which would essentially only lerp them on a single frame to that next step, if they were rotating, for example, and they'd display that static angle until the next step is reached, meaning that, if the animation were smoothly animated as it was normally (without broken/stepped tangents -- just default Unity curves), they'd be at the exact same angle on that 'step' frame that they would be without any stepped curves/tangents.

    Essentially, I want to make the curves between all selected keyframes bridge their timing gap (and still maintain their orientation as if they were actively being rotated by the engine's usual curve algorithm in the case that a step value is above 0), filling that timing gap by a specific number of steps (or paused frame displays) between each of the frames.

    To clarify:

    If I have 6 keyframes selected, and I right-click one of them from the keyframe editor, I should be able to set frames 1-5 to have a stepped timing pattern between them to 5, for example, which means 5 steps of resolution between frames 1 and 2, and 5 steps of timing resolution between 2 and 3, and so on, all the way up to the 6th frame, which has its default value/tangent/curve timing. If there are any frames in the animation after that 5th one, they will retain their curve/tangents/etc., but I should be able to click and drag on the rest of the frames and set their tangents to 0, meaning an instantaneous transition to their next frames without any lerping/smoothing/step-resolution/etc. as soon as the next frame is reached (and, at 0 step resolution, the previous frame will stay displayed until that point). If by chance the step-resolution for those frames are set to 1 or greater, the frame of a rotated sprite, for example, is put at 50% its lerped rotation halfway through the empty space in the animation (with step-resolution at 1 for those frames), and 25% rotation completion if the step-resolution is 3, and so-on and so-forth.

    I hope this was clear because this is a style of animation that can mimic sprite-based animation, without the requirement of a sprite sheet and a huge amount of memory overhead for lots of animations, as is the case for me. I would be able to use pixel-looking parts for my sprites rather than full-drawings while still maintaining the look of a frame-by-frame animation common to sprites of old. As an added bonus, this would allow stop-motion-looking effects for 3d animation, which leads to all sort of unique-looking games Unity is currently not capable of supporting easily with its animation system. The problem of creating animation like this would at least be manageable if only you guys would support this feature. I prefer to use Unity to do ALL my creative work wherever I can, so I really do need the tools it has to work for me instead of against me. :(
     
    Last edited: Aug 2, 2016
  27. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    I don't think we'll add a stop motion generation feature anytime soon. That's a feature that's not that complicated to implement on the user-side, and is a good use case for an Asset Store package.

    Here's a few ways you can already achieve this:

    1- Manually Update your Animators
    Just use normal animations, and manually update your animator on whatever frequency you choose.
    Upsides:
    * This uses less keyframes (so less memory), and only animates your characters when they actually need to move
    * This lets you make sure that your steps all have the exact same timing, whereas if the stop motion is part of your animation, there is no guarantee that all your "steps" will fall evenly on render frames, and the motion won't be as smooth.
    Downsides:
    * This doesn't let you preview your animation easily in the animation window.
    * Manually updated animators don't take advantage of multithreading

    2- Set the animator speed to zero on most frames, animator speed to 1 on update frames
    Same idea as the previous one, but lets you take advantage of multithreading.

    3- If you must absolutely bake your stop-motion in your clips, you can also write a script that converts an existing clip with a few keyframes into a stop motion clip. You basically need to create a new clip from your existing normal clip, but automatically create stepped keys at fixed intervals from the values in the original clip. This way, you get a new clip that's stepped, but you get to keep your original clip, with less frames, that's easier to animate.

    You can take a look at AnimationUtility (https://docs.unity3d.com/ScriptReference/AnimationUtility.html), most of the functions that are necessary are in there:
    GetCurveBindings to get all the curve identifiers from your clip
    GetEditorCurve to get the curve from the clip
    SetEditorCurve to set a curve on the new clip
    From other places in the doc:
    AnimationCurve.Evaluate to evaluate a curve at a specific time
    AnimationCurve.AddKey to add your new keys
    AssetDatabase.CreateAsset to save your new animation clip on disk
     
  28. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    @DavidGeoffroy
    To be honest, I've considered writing an asset to do this, but as far rewriting the entire built-in animation clip editor to achieve something so simple as an animation preview is kind of insane when all one needs is a native curve-step-resolution command in the keyframe editor itself, allowing one to cleanly preview one's animation without fiddling with curves and duplicate animation clips.

    Adding a curve-step-resolution pop-up to the keyframe editor would allow a LOT more than just stop-motion. For example:

    • high-res, modular, memory-saving, part-based animation not reliant on old-school sprite sheets
    • rigid one-frame animation effects when required in an otherwise curve-based animation
    • accurate in-engine previews of this type of animation
    • seamless simulation of typical sprite + hand-drawn animation, mixed w/ modular animation support when complex animations are required -- which is something you cannot easily do with sprite sheets animation alone
    • swift, anime-looking actions, with a strong 'pop' for fast movements (like a snappy punch) not currently possible in a typical 3d (or even 2d) non-hybridized curve-based animation approach

    This is all coming from an animator who would rather animate than find/buy or produce tools for ancient features one would expect to already be present in a modern animation tool of any sort.

    It's already hard enough to create quality content for our games -- so why not help us make it a little easier?

    And to finalize my point -- the downsides you mentioned are already VERY BIG downsides, especially when dealing with mobile (and, afaik, a majority of 2d games made in Unity nowadays are indeed mobile), so performance and memory are both critical issues. Why not offer one more option to distinguish the look of our games -- especially if the overhead for a feature like this, comparatively speaking, is exponentially small and efficient for all parties in the long-run?

    At most, two separate pop-up menus (one with a numeric input-box) and a few lines of code to auto-create the steps/breaks in the selected keyframe(s) curves would be all that's required on Unity's part -- and for that little bit of effort, your customers (and potential admirers!) would still be able to maintain standard Unity animation previews, multi-threaded performance (i.e. on mobile devices), and an infinitely-better workflow! -- all without any contrived animation/clip-duplication systems or sacrifices in speed/quality that you pretty much confirmed would happen even in the best 3rd-party assets. Relying on the asset creators for problems like these is a dangerous, slippery, slippery, slope. Devs like myself, who are artists/animators at heart, rely on the Unity team -- not the asset store -- to give us the solutions to all the "tiny" problems we face.


    To get back on topic -- I suppose the best solution you offered seems to be your number 2 since you can somewhat maintain a preview without duplicate animation -- but I've no idea how this might work. Could one use animation events in the editor for this so it could account for the exact keyframes where the timing is required to change? If so, what would the code look like for that for something like that? After all, if you set the animation speed to 0, does that not stop the animation entirely? Will this work with legacy or mecanim? Or can it work for both?
     
    Last edited: Aug 3, 2016
    X2DGmDev, MitchC and theANMATOR2b like this.
  29. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    @Mecanim-Dev or @DavidGeoffroy

    I know you guys are very busy, but I've stated valid points against the proposed solutions in a reasonable way, and I would expect the same sort of response in kind.

    Any official reply or a proper solution to the aforementioned issues?

    Writing (or buying!) a very limited and sub-par asset to band-aid this glaring "under-the-hood" issue simply wouldn't be a reasonable (or fair!) solution to your users!

    In the end, we have sub-par animation-implementations spawned by tools we simply can't use for common use-cases -- tools that still need some TLC so that we can work on all varieties of animation-assets intuitively and effectively within them.

    This type of animation is not new -- and is in high-demand! Spine, for example, currently a very popular program, as well as Spriter, all use the modular animation approach mentioned above, and allow for frame-by-frame or stair-stepped editing -- intuitively, and across multiple platforms -- while also implementing curves inside the very same 'stepped' animations, and why Unity cannot implement such a tiny interface tweak (a pop-up on right-clicking the key) to allow the same type of animation is simply beyond me.

    Letting this type of animation be applicable to ALL animation curves, including 3d, would make the default tool an exponentially more powerful tool -- and you can't go wrong with that. Considering many users are becoming disheartened by UT's whole "go to the Asset Store and spend money on 'x' feature since we got a lot of work to do and can't be arsed to do it ourselves" approach that seems to be so prevalent with such badly-needed features. UT is not specific in this regard, but this is one way you guys could really stand out to users like myself who've left other software packages for less, seeing Unity as a light at the end of a long tunnel. :(

    The editor lags behind in many basic features common in the industry today -- which includes many features for basic animation control -- which something like stepped-animation shouldn't even be an issue in an engine that prides itself on its visual prowess! Control over something like this should be built in. This just brings up another issue: the reason why people still use the 'Legacy' animation system. The reason is quite simply that they have more CONTROL over their animation this way and how it displays! This stuff is very important to animators. Frame by frame animation is BASIC and should be IN already.

    That all being said, I rest my case.

    It's now up to you guys to respond to tell me why I am wrong to expect this 'feature'.

    Besides, Creative people LOVE control -- the more creative control you give them (intuitive control of course), the happier they'll be. This includes people like myself, who just want to see Unity cover its bases in the animation-control department too!
     
    Last edited: Aug 12, 2016
  30. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    so what is the solution to this in Unity 4.7? duplicate the clip and manually edit in unity? really???

    hope one of the dev's at Unity who knows the internals posts a script to automate this process to fix animations that are imported with stepped channels.
     
  31. MitchC

    MitchC

    Joined:
    Sep 9, 2013
    Posts:
    22
    Just came across this thread looking for a solution to importing stepped keys. I agree with what @awesomedata has posted, it seems pretty silly to leave such a basic, fundamental animation option up to a hypothetical Asset Store addon. One of my dream games to create in the future would pretty much need the ability to import stepped animation, so it's pretty disappointing to hear that it's not really seen as an important feature.
     
  32. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Ok...
    This thread is super long, and touches way too many different subjects, and there's quite a bit of confusion. I'll try to clarify:

    Importing stepped Curves
    1- Up until Unity 5.3, unity always resampled all animation curves. This destroys all keyframes, and creates new ones. So no imported Stepped Keys.

    I don't know why it was like this; this was decided waaaay before my time.

    But one reason for it is: DCC Tools (Maya, Motion Builder, Blender and so on) author rotations in Euler, and Unity deals with rotations in Quaternions. You can't convert Euler keys to Quaternion directly. So stepped keys get destroyed, the Euler Curve is re-evaluated every frame, and a new key is created in Unity for every frame, to ensure that "on-frame", your animation looks the same.

    When it comes to baking, this is industry standard.
    Of course, this is terrible for stepped keys. Because of this;

    2- In 5.3, we introduced an option to turn off resampled curves.

    But this is not as simple as just offering an option. To do this, you need to make sure you support Euler curves natively.
    This necessitated introducing a completely new type of curve to the whole animation pipeline, supporting every different rotation order, and adding support for (actual) Euler curve type to the Animation Window.

    This was roughly three months of work full time. This was 3 months of my life, so please believe me when I say that I care.

    All of this lets you import stepped curves since 5.3. With some restrictions:

    3- Restrictions:
    Unity doesn't support pre- and post- rotations. So if you use those, your rotation curves will be resampled, even with resample curves at off. There's no way around it. There are no plans in the short term to support pre- and post- rotations, so if you need stepped keys on your rotations, don't use pre- or pos-rotations.

    The resample curves option doesn't exist for Humanoid. In order to retarget animations, Humanoid resamples all the curves and converts them to another format, so the stepped keys get destroyed.

    The resample curves option has also been disabled for Legacy Animations. The reason for this is fairly simple: the Animation Component is not capable of blending Euler rotations and Quaternion rotations together correctly. Fixing this would basically require rewriting the whole Animation Component, which is a very risky proposition, considering one of the main selling points of the Animation Component is that it's simple and stable.

    Okay but I really want to disable resample curves in Legacy
    If you know what you're doing, and want to use Euler in Legacy, there are a few ways you can work around it:
    * You can import in Generic, copy your clips and change them to Legacy. For imported animations, there should be no difference between the two, and it should work out of the box. You can change a (copied) animation to legacy through the debug inspector, or through script.
    * The resample Curves option is also available through the API: https://docs.unity3d.com/ScriptReference/ModelImporter-resampleCurves.html. So you can set it even though it's not available in the UI.
    * you can edit the .meta file too

    4- Supporting this Pre-5.3:
    This is way too big a change, that touches everything. I'm sorry, if you want to import Stepped Curves, you need at least 5.3. I wish we had fixed it before, but I can't go back and fix it before I was hired.

    5- Will this ever be fully supported in Legacy?
    Maybe. But there are no plans for the moment. Supporting this would probably mean slowing down the Animation Component a bit, which would impact quite a few users.

    In the Animation Window
    In the Animation Window, you can create as many Stepped Keys as you want.

    What about Stop Motion?
    Having built-in stop motion would be nice, but it's useful only for a tiny fraction of Unity users. We have plenty of good suggestions on https://feedback.unity3d.com/ that we need to address before this, because they will benefit more users.

    You can make your own stop motion by making stepped keys, or importing stepped keys from an authoring software that supports it, using the information above, or by automating it in Unity.
     
    awesomedata and theANMATOR2b like this.
  33. SeruK

    SeruK

    Joined:
    Sep 22, 2016
    Posts:
    12

    Hi David,

    Thanks making this a bit more clear. We've had issues with cuts (i.e. instant transform changes) in cutscenes in Unity for two games now. Basically a stepped curve is used in 3DSMax, but since it's resampled the instant cut becomes two keyframes (with 1 / 30 seconds inbetween - I'll get back to this). When this is played at >30 FPS (which is what they are animated in) the interpolation between these two frames is sadly very jarring.

    Now we know why the curves come out looking like that, it's because they're resampled, cool. Before reading your post I simply thought that was how Unity always did things. So our solution was to export the cutscenes at 60 FPS and fix step the animator manually. Kind of a convoluted solution, as we could use AnimatePhysics to ensure there are no "middle frames", but we want >30 FPS cutscenes and physics not to run at 60 (duh). Alas, not even this was a viable solution anyway, since apparently when the curves are resampled the one-frame-value change the stepped curve is translated into does not seem to take the frame rate of the animation clip into account, as it actually put those keys 1 / 30 seconds between each other. When resampling curves, this should probably be 1 / 60, unless I'm missing something? Basically, unless we'd fix the curves manually, we'd be stuck at 30.

    Now that I've read your post it seems that Unity _does_ have support for not resampling curves (we're on 5.4), which is great. But our animations still come out with wrong curves, even though the option is deselected. So from what I've gathered this is because Unity is actually resampling the curves, but not telling us about it. After running quite a few tests, it seems like basically this resampling happens any time we have a non-stepped animation curve that changes rotation values.

    I'm guessing this is because of the pre- and postrotations you mention? Could you please expand on what that means exactly? I've found it a bit hard to find information on what those conceps are exactly (something-something two different ways of describing rotation changes). In 3DSMax, all the animator does is rotate a keyframe, is there some kind of export setting we've missed? I mean, there _has_ to be a way to have a non-stepped rotation curve in non-resampled curve, right?

    Just as an aside, I _really_ think you ought to tell the user that the curve is resampled and why. Like, grey-out the Resample Curves toggle and give a little message. We had no idea our problem was related to it and no way of knowing besides coming here and reading your post.
     
  34. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Just want to say thank you and the team for putting in the effort and time on this. You are part of all of our teams - even the lone indie like me who should give equal credit to you (as our lead tech artist) for solving complex issues like this one.
    I noticed Max was not included specifically except to be included as 'and so on'. Was this explicit because Max does support Quaternion rotations when using biped?
    upload_2016-9-22_10-7-23.png

    I have the same request as @SeruK Could you explain in laymen/artist animator terms what pre- and post- rotations actually is?
    I've been animating for over a decade and a half and this term doesn't really mean anything to me. Attempting a guess I would think this means any rotations before or after a set stepped keyframe, that would be auto resampled when imported into Unity, even with the option to resample turned off. But this can't be right - because that would basically mean all rotation curves would be resampled. The only stepped keys that would not be resampled would be the transformation keys.
    Thanks for the clarification (using animator terminology) on this.
     
  35. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    The short answer is yes, it should be possible, but I don't really know enough about 3DS max.

    The (very) long answer follows:

    What are pre rotations

    Here's a screenshot from MotionBuilder:
    upload_2016-9-22_15-57-51.png

    I think it's different in 3DSMax, but I don't know 3DSMax enough, and my Google-fu failed me.
    But this (http://help.autodesk.com/view/FBX/2...GUID_10CDD63C_79C1_4F2D_BB28_AD2BE65A02ED_htm)

    makes me think that in 3DSMax, it (loosely) maps to pivot rotation, pivot translation and pivot scale (which I'm fairly certain we don't support either)


    Let's stick to pre/post rotations to keep things simple (well simpler)

    Pre and post rotations are properties of your bones. They are usually used by the rigger to setup the joint in a way that the 0,0,0 animated value faces in a different orientation than the default orientation of the bone in the model. This is done to avoid gimbal lock when otherwise most of your rotations would be something like (90,90,90), which is usually problematic.

    Gimbal lock? Another thing I have to understand?
    Here's a video I found that explains Gimbal Lock quite well:


    Ok, got it, so... pre rotations? Please get to the point, this is boring
    Right..
    Here's the way pre/post rotations work:
    1- Rotate the joint by pre-rotation (r1)
    2- Apply animation rotation (r2)
    3- Rotate the joint by post-rotation (usually back to the original rotation, but sometimes not) (r3)

    If you animate those joints, the rotation that's saved in your curves (r2) is completely different from the actual rotation that's applied to your bones (which is basically r1*r2*r3)

    Importing in Unity
    When we import animations (without resampling), we tell the FBX SDK:
    Here's what we support:
    - No pre rotation
    - No post rotation
    - any rotation order (see the video above for rotation order too)
    Please give us something that works for this.

    Then the FBX SDK decides if it can give us the data from the FBX file directly, or if it need to convert it.
    When there are pre or post rotations, the FBX SDK automatically converts the whole curve to quaternion (made from r1*r2*r3) and this is what we save to the animation clip. This is where your beautiful, spartan stepped curves become those sloppy S-shaped abominations

    So... this is really long, what should I do to get this working properly?
    Motion Builder: no pre-post rotations
    3DS Max: no pivot rotation, translation or scale (probably?)

    Answers for the rest coming in the next reply (I'm afraid to lose this wall of text at this point)
     
    theANMATOR2b likes this.
  36. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Yes, I think I think it's clear we need to give more feedback on this.
    Since it's done on a curve by curve basis, and the animation importer setting spans all clips in a file, we can't show this in the checkbox, but we should definitely be able to show warnings when resample curves is off, and a curve still needs to be resampled. I'll see what I can do. FBX SDK is somewhat of a black box.

    I didn't mention it because I'm really not familiar with 3DS max, and all my coworkers haven't touched 3DS max in ages.
    As I mentioned in the previous post, I think pivots in 3DS max are the issue, but I don't have a 3DS max license right now, so I can't test this.

    As for animating using quaternions, I don't think it changes anything. Pre and post rotations (and geometric rotations) still get applied, and we get the same issue. because the interpolation you expect between keys with those rotations has no relation to the interpolation you get when you compound them together
     
  37. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    This sounds like a bug.
    I think it should resample at the framerate from the file, but there may be concerns of which I'm not aware.
    Please file a bug with your file and paste the bug # here.

    I'm not promising an ETA, but at the very least it won't slip through the cracks.
     
  38. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    If you need an external test performed in Max feel free to shoot me a PM with it outlined.

    Thanks a bunch for the information.
     
  39. SeruK

    SeruK

    Joined:
    Sep 22, 2016
    Posts:
    12
    Hi again David,

    Thank you for your lengthy and informative reply, I feel like I got much more of a grasp of the issue.

    Before finding your reply I sent two bug reports which I now realize was a bit illinformed. Just thought I'd let you know if any of them wind up on your desk.

    FBX Stepped Curves Not Imported Correctly
    https://fogbugz.unity3d.com/default.asp?833901_dc0jqmt9tfv025mr
    Animation curves with constant angles gets interpolated transitions
    https://fogbugz.unity3d.com/default.asp?833907_us1t7k8f1d6bgbbv

    I filed a new bug report which should cover more of the issues we have here, including the 1 / 30 sampling bug (I thought I might as well include as much as possible for context, because I don't know if it should translate the curves like that in the first place):

    Resampled FBX Curves Discrepencies
    https://fogbugz.unity3d.com/default.asp?834635_rdcthiclctt6gc4i

    Here's the project that I also attached to the bug report if you want to look into it.

    Okay, so I just want to mention that if you inspect an FBX in ASCII (all the FBX:s in the project are) there are properties that are called Pre- and Postrotation. On of these seems to be translated into the "base rotation" that the model has in Unity, but it does not affect whether the curves need to be resampled or not.

    Basically, I've narrowed our issue down to one thing: non-stepped rotation curves. This makes sense if pre- and postrotation are not supported and if that's just how 3DSMax translated those changes. Basically, the only thing our animators do is rotate a bone with the rotation tool. If this unknowingly to us causes rotation via pre- and post under the hood, or somehow pokes the pivot values or whatever... well then we know what the issue is, but not really how to solve it.

    I'll check if there's _any_ option in 3DSMax to export/handle rotations in some other way.

    So this is interesting, because this does not seem to happen curve-by-curve. Even though it should only be the rotation curves that would need resampling, the position curves of the same object is changed as well. If it's not everything that's resampled, it looks like it's at least per-transform?

    I didn't include that the user does not get information about curves being resampled in the bug report, but I'm assuming you're on it somehow :)
     
  40. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542

    833901 has just been added to our bag (it was reproduced by QA)
    Here's a screenshot of one of the curves in 833901 when opened in Motion Builder 2011(what I have installed locally)
    upload_2016-9-23_10-45-5.png

    And here's a screenshot of the same curve in 3DS Max 2016
    upload_2016-9-23_10-52-31.png

    This definitely looks like a FBX export issue (even before it gets to Unity). When we get the curve, it's already resampled, so there's not much we can do.

    But, could you update one of the bugs with one of the source files (3ds files)? I'd really like to get to the bottom of this once and for all.
     
  41. SeruK

    SeruK

    Joined:
    Sep 22, 2016
    Posts:
    12
    Hey David,

    It certainly does look like an export issue, and we were able to reproduce it. Export with a rotation curve that is unstepped - resampled curves when opening the FBX in Max. Export with the same curve but stepped - no resampling, FBX imports fine.

    I couldn't figure out how to attach a file to the existing bug rapport, but here is the Max file. It's basically the original Max file but with everything except the camera stripped out.

    EDIT: The reason we didn't think it was an export issue initially is because we've had this problem for multiple projects and years, and past FBX:s did not have their keys resampled when reimported into Max. This makes sense if not resampling is as new as 5.3.
     
  42. SeruK

    SeruK

    Joined:
    Sep 22, 2016
    Posts:
    12
    Hi again David,

    Have you made any progress on this issue?
     
  43. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Not yet. I keep poking at this on my spare time though.

    I've asked 3 of our animators so far (the last one was last friday), and not one was aware of that issue, or how to work around it.

    Everything I found online says: "Bake Animation", which is exactly what you want to avoid, so it's not exactly helpful
    The next step is to request a 3DS license.
    I'll update you when I have more info.
     
  44. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Ok..

    I found things that export/import correctly:
    A) Basic primitives (Bones, points, cubes, etc) that are not at the Root of the scene, with default settings

    I found things that export to FBX by baking, so you'll lose your stepped keys
    B) Cameras
    C) Others?

    And I found things that exported correctly, but imported incorrectly in Unity:
    D) Pretty much anything in A) but at the root of the scene;

    This is about as far as I'm investigating. I can't do much about B) and C); the problem is definitely between FBX and 3DSMax.
    As for D), I'm looking to see if I can fix D).

    Otherwise, if you need to animate a camera using stepped keys, you'll need to animate the rotation and position on a proxy object that's not a root node.

    I've attached an example package (.fbx file and .max file) of things that are working correctly.

    As a general rule, if something is doing processing for you
    * keeping the up vector constant (camera I think)
    * constraining a rotation (IK)
    * indirectly moving something (sliders and other controllers)
    * physics
    ... it will probably have to be baked, and you'll lose precise control of it.
     

    Attached Files:

    theANMATOR2b likes this.
  45. SeruK

    SeruK

    Joined:
    Sep 22, 2016
    Posts:
    12
    Thanks a lot for staying on this, David.

    Thing is, we should just be exporting animations, so no camera should be included at export time? We do have a camera in our Max scene though, so we'll try removing that and see what happens...
     
  46. SeruK

    SeruK

    Joined:
    Sep 22, 2016
    Posts:
    12
    Did a quick test where I removed the Camera from the Max scene but to no avail.

    Still the only thing that seems to work is not having _any_ non-stepped rotation curves in our cutscenes which is not a viable solution.

    It's starting to look like we should just try contacting Autodesk somehow. Don't know how much they can/will help though.
     
  47. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Is this the scene from 833901?
     
  48. SeruK

    SeruK

    Joined:
    Sep 22, 2016
    Posts:
    12
    Very sorry for the very late reply! I did not have email notifications and was caught up in other tasks. I think I was able to turn them on now.

    No, it was the one I linked in #41, this one. I think however it might be based on the same FisherOutro scene in 833901, only having everything but the camera stripped out?

    Right now we're going to and fro this task (whenever we remember it) as there are a lot of things to do right now, but we have decided that we (a tech-artist and I) will move back to it next week and actually dedicate a day to do some more tests.
     
  49. tealm

    tealm

    Joined:
    Feb 4, 2014
    Posts:
    108
    Just wanted to say that I'm very happy with Unity fixing this issue! Stepped animation keys are working great here now! We had to convert this manually before (duplicating clip, and selecting all keys -> stepped in Unity) - and it's a relief to not have to worry about this now.

    So thanks again @DavidGeoffroy !
     
    theANMATOR2b likes this.
  50. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    I want to second that. Thank you guys for fixing this issue!

    Great to see Unity is listening! :)
     
    theANMATOR2b likes this.