Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mecanim and script bone controlled

Discussion in 'Editor & General Support' started by 3Nu, Nov 27, 2012.

  1. 3Nu

    3Nu

    Joined:
    Feb 13, 2011
    Posts:
    18
    Hi all, I'm trying to move the neck of my character from script. The character has an animator controller attached, and a simple idle animation on the base layer. If i remove the Controller from the animator, I'm able to move the neck, otherwise I'm not.

    I'm rotating the neck inside the LateUpdate function ( which AFAIK it is called AFTER OnAnimatorMove() ). What's happening is that I see a little movement of the head's neck, but the frame after, the neck is replaced in the position according to the idle animation, such as Unity is drawing between Late/Update() and OnAnimationMove() calls.

    If I move things inside OnAnimatorMove(), nothing happens, as bones transfomations are not affected by the user operation.

    Finally, my character uses generic animations so far, as the humanoid rig is not finished yet.

    Any hint? Am I missing something?

    Thanks,
     
    Last edited: Nov 27, 2012
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Mecanim does write into transform after OnAnimatorMove() and OnAnimatorIK().
    So you are doing the right thing when you change the neck rotation in LateUpdate(). But Mecanim doesn't read back these values since it driven by animation clip. You need to update your transform at each frame if you want to keep your offset.

    What are you trying to do exactly? maybe there is another way to do the same thing.

    Sonny
     
  3. 3Nu

    3Nu

    Joined:
    Feb 13, 2011
    Posts:
    18
    So, if I get it correctly, you are suggesting to keep the transofrmation matrix of the bone, update it each frame, and then simply replace the bone's one (driven by Macanim) with that. I will give it a try, thanks.

    What I'm trying to implement is a kind of Animator.SetLookAtPosition() with a generic skeleton (not humanoid).
    This could be simply substituted in the future if we swap to a humanoid skeleton, but a simplar technique could be used for lip sync, if we decide to drive bones by scripting.

    I'll let you know, thanks.
     
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    For mecanim Animator.SetLookAtPosition is called at each frame because the target and character position could change so we need to compute the new head orientation at each frame.
    Also we do provide a weight to blend in and out the animation otherwise your head will change orientation in 1 frame.
     
  5. huang

    huang

    Joined:
    Aug 16, 2012
    Posts:
    34
    i call the SetLookAtPosition function , if i change the target position, but the character head doesn't rotate by the target.

    thanks!


     
  6. FrederikGrünzahn

    FrederikGrünzahn

    Joined:
    Nov 30, 2012
    Posts:
    2
    Hi,

    I am experiencing the same problem: I try to modify a mecanim pose by a "handcrafted" IK method. Unfortunately modifying the animation in "LateUpdate" does no longer work and I have inconsisent results like 3Nu. In some frames the correct result is visible, in some frames the original animation. You may see here, where I try to add a simple rotation to the idle animation generated by mecanim : http://depot.tu-dortmund.de/get/e2lws (sorry for bad quality).

    So the statement:

    does not prove to be true in Unity 4.0.0.f7.

    Reverting to the legacy animation system fixes the problem.

    I can only think of PITA solutions to integrate with mecanim like:
    -using a second skeleton for each character
    -abusing the OnPre/Post Render to run surely after mecanim

    Unfortunately I see no clean solution to integrate with mecanim - i have also issued a question to unity support about this.

    Glad for any help,
    Thanks,
    Frederik
     
  7. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    To have Mecanim IK work:

    * you must activate IK Pass on at least one Layer ( in Mecanim Controller tool, there is a Layer section at the top left)
    * have pro version
    * call SetLookAtPosition in the OnAnimatorIK(int layerIndex) callback
     
  8. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    This seems like a bug, IsAnimatePhysic set to true on the animator ?
     
  9. 3Nu

    3Nu

    Joined:
    Feb 13, 2011
    Posts:
    18
    It was my first try too, but no luck at all. It gives the same result whether you switch it on or off.

    Moreover, I've noticed that OnAnimatorMove() is called per each character's bone in the skinned mesh. So my next question is; If this is intentional, why do we get a callback with a void parameter and we do not get at least the index of the bone that Mecanim is going to change?
     
  10. pierrepaul

    pierrepaul

    Unity Technologies

    Joined:
    Jun 19, 2012
    Posts:
    162
    Can you log it has a bug please ?

    Its called once per character. The goal of the callback is to adjust the root movement ( based on physics for example)
     
  11. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    In other words Mecanim has become too complex. Now too many options have been introduced as a good gesture but have backfired. The Mecanim should have been incorporated as part of the Legacy system but now they are distinct. I hope in future releases things will change.
    I myself looked to Mecanim as a retargetting solution but that backfired as the Retargetting fails with Legacy animations. Mecanim unfortuneately didn't introduce a once and for all retargetting solution.

    Its good for a very "limited" aspect of games but Unity is very broad. I however have been Using Unity for a long time. And I know the main reason I kept with Unity was because of the Community - I got bashed a lot but these people helped me become better. So I know I can count on The guys at Unity to make the changes needed. As for me I hope the next Unity is the Windows 7 to the Windows Vista.

    I was so exited at the Changes in Unity 4 but soon found Unity 4 introduced more problems than solutions. Unity was very much Hype this time. But I remember Unity 3 having a similar experience - Unity 3.5 is when I was Wowed. So lets Hope :).
     
  12. FrederikGrünzahn

    FrederikGrünzahn

    Joined:
    Nov 30, 2012
    Posts:
    2
    Hey all!

    I am very sorry but Mecanim seems to work fine for me, so no bug at all.

    For some reasons I have set IsAnimatePhysics to true in the animator. While building a test case I noticed that this is causing the problems I had.
    When IsAnimatePhysics is set to false, I can access the pose in LateUpdate without problems. I don´t remember why I switched it on in the first place. So all shame on me :-\

    Thanks for your superb support, I really appreciate this and good luck while developing the new release. I am really looking forward to a tighter script integration of mecanim, but I am sure you will built this over time. For instance it would be very valuable to us to access the automagicly (thanks!) registered bones to initialise our own routines.
     
  13. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    I can't say I've had anywhere near the same experience as you. I do think they should keep the legacy Animation system (there are a few limited situations where Mecanim just wouldn't work), but for game characters I see no reason at all they shouldn't use Mecanim in it's entirety. Need head look? Just use the built-in IK features. Seems pretty easy to me.

    I think Unity 4 has done nothing but improve upon an already great engine, and it's finally bringing Unity up to par with it's uber-expensive alternatives.
     
  14. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    You well that comment was actually quite some time ago, since then I found many more major issues in which I sort of gave up Game Development since Unity 4 took the Joy out of it. For me I was working with a very memory intensive import and I kept getting memory crashes. Eventually - you know how it goes you focus your attention on one bad aspect and then find many others, all in all I had found many bugs with this version of Unity and many steps backward. But I just can't be bothered anymore. The fun factor of game development left me, so I am pretty much finishing up my last game and then quitting the scene.

    I think some people just flow when its right for them, I had to force my way through game development and eventually I just know it was a waste.
    But as their are quitters theirs successers ....ah don't mind spelling I can't be bothered. Good Luck tho!
     
  15. HamFar

    HamFar

    Joined:
    Nov 16, 2014
    Posts:
    89
    Hi Sonny,
    Where are these 2 scripts: OnAnimatorMove() and OnAnimatorIK() ?
    Thanks
     
  16. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675