Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Update Bone Positions After Animation with "Animate Physics"

Discussion in 'Animation' started by DDNA, Sep 20, 2016.

  1. DDNA

    DDNA

    Joined:
    Oct 15, 2013
    Posts:
    116
    I want to change the bone positions in script after the animation runs. This works fine if I put this code in LateUpdate. But I need to run my animator with "Animate Physics" so as far as I understand the animation is running in the FixedUpdate cycle. Sine there is no LateFixedUpdate there is no place for this code to be.

    What is the right way to do this?
     
  2. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,573
    Could you give us a little bit more information on what you are trying to achieve?
    How are you going to move this bone? with a physic force or simply set a new position?

    Are you trying to implement a ragdoll to animation blending?
     
  3. DDNA

    DDNA

    Joined:
    Oct 15, 2013
    Posts:
    116
    >Are you trying to implement a ragdoll to animation blending?

    Yes this.

    I am running 2 skeletons and blending them. One with animation and one with a Ragdoll. I am blending them but at some point I will probably want to mask off bones to have them be controlled by animation or ragdoll.
     
  4. DDNA

    DDNA

    Joined:
    Oct 15, 2013
    Posts:
    116
    I don't understand why Unity is so stubborn about adding a LateFixedUpdate it is something people have been asking for years.
     
  5. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,573
  6. DDNA

    DDNA

    Joined:
    Oct 15, 2013
    Posts:
    116
    If you take this example and change the animator to "Animate Physics" it doesn't work anymore.



    This is because what he is doing in LateUpdate now needs to be done in the Fictional LateFixedUpdate. Which is really the point of the question.

    We found a "solution" to this. We have this kludgey system in-place to deliver a LateFixedUpdate, using some bizarre use of a yeild statement to force unity to give us an opportunity to do something after the animator. We had this in place already because we needed a LateFixedUpdate for other things. It sucks that Unity can't just provide this and we have to resort to things like this. It leaves me in fear that this side effect behavior will stop working at some point.
     
  7. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,573
    well that sucks, effectively it seem there is no way right now to fix this issue and honestly the current solution to blend from physic to animation is way to complex.

    I will bring this to the animation team meeting and we will find a better solution.
    As for the LateFixedUpdate I will talk with the scripting team to get their thought about this one.
     
    awesomedata likes this.
  8. DDNA

    DDNA

    Joined:
    Oct 15, 2013
    Posts:
    116
    Thank you so much.
     
  9. alice_funo

    alice_funo

    Joined:
    Mar 9, 2016
    Posts:
    14
    I'm also having the same problem since we have to use AnimatePhysics mode (it's a hard requirement for our game).

    The way I have tried to rig it, is to have a "PostFixedUpdate" function that is called before every FixedUpdate and Update -- only if a FixedUpdate has occurred (evident by using timestamps). I still have to keep some timestamps because everything called inside PostFixedUpdate cannot rely on Time.deltaTime anymore (we don't know if we have multiple updates in a row, or fixed updates in a row, etc).

    In short, it will be really nice to have a callback *after* animation is done, so we can apply things like procedural rotations and full body IK
     
  10. Sokharev

    Sokharev

    Joined:
    Oct 10, 2013
    Posts:
    7
    Hello, i've faced the same problem(but not for ragdolls) and tried following to deal:
    1. add StateMachineBehaviour to your states where you're need PostFixedUpdate
    2. add your code to OnStateUpdate section
    3. profit(?!)(perhaps?)
    Actually it doesn't solved my problem, but as i see in "Timeline" section of profiler it doing update exactly after "animations" update(when you're in PhysicsUpdate mode) - so _may_ be it can be ok for you.
     
    Last edited: Nov 24, 2016
  11. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,573
    Well yes the OnStateUpdate will be called after the Animation Update but the the animation system has not yet written all the animated values to unity so you can't override the values in this callback.

    But we are currently changing the animation system to behave more correctly with physic. Rather than overriding animation values in a LateFixedUpdate we want to add a new blending phase after the physic update.
     
  12. Sokharev

    Sokharev

    Joined:
    Oct 10, 2013
    Posts:
    7
    Nice to hear, any suggestions on release time?
     
  13. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,573
    I can tell you that it won't be in 5.6, maybe the next release after if everything goes well
     
  14. Malbers

    Malbers

    Joined:
    Aug 7, 2015
    Posts:
    1,150
    Hi guys, well its good to find this :)

    because Im having this problem since forever, accidentally discover that it was because I was using Animate Physics mode, on update mode works fine but again I need the Animate Physics mode to my characters, and the get the same strange behaviour as @DDNA ..

    @Mecanim-Dev any new hints on this? same issue on all unity versions :)
     
  15. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,573
    The feature is currently in developpement, so it going forward but I have no idea when it will be available yet.
     
    awesomedata and Malbers like this.
  16. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    556

    Is this coming with the new Timeline system, or is it still in the planning phases?

    I am working on something that needs to be tied closely to physics (but not rely on it entirely) and I'd really prefer to know how performant this will be in Unity if I have to roll my own solution with manually setting transforms.

    Here's what I've gotta implement in Unity, and I've got to have bone-level physics control to do it:

    http://www.gdcvault.com/play/1020583/Animation-Bootcamp-An-Indie-Approach

    Any thoughts on a good performant approach to spring physics and secondary motions being combined with the custom blending curve interpolation necessary to achieve what's in that video inside of Unity, @Mecanim-Dev ?