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

Access a bone from script, Mecanim

Discussion in 'Animation' started by Maguelonne19, Feb 4, 2015.

  1. Maguelonne19

    Maguelonne19

    Joined:
    Jan 29, 2015
    Posts:
    8
    Hi ,
    I am using mecanim animations, i imported some models from MakeHuman and animated them with animations from the assets store. Everything goes well. Now I would like to see if I can access a specific bone (like the neck) from script.
    I wonder if it is possible to access a bone, not as a Transform but the actual Mecanim bone. I have been looking for that since a few days and I cannot tell if it is doable and if my request makes any sense.
    I would be happy to hear your opinion!
    Thanks.
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Hi Maguelonne19,

    What is your use case exactly? What would you like to do?
     
  3. Maguelonne19

    Maguelonne19

    Joined:
    Jan 29, 2015
    Posts:
    8
    I would like my character to move her face, so i want to edit the neck bone but not by accessing the gameobject. I'd like to know if accessing the real bone is something doable in unity ?
    When we configure the avatar and do the bone mapping, mecanim shows that it understands the bone structure. So i have been wondering if bone is a structure/element that we can access from the script. Unfortunately, the more I search about that the more i think that we can only access them as gameobjects.
    I hope you understand my request and can help me :)
    Thanks
     
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Yes so in your case you would like to edit the neck transform after mecanim animation step, to like override what the animation system did compute right?

    In this case you only need to modify Unity transform component directly but you need to do it in a LateUpdate() callback
    http://docs.unity3d.com/ScriptReference/MonoBehaviour.LateUpdate.html

    so you would do something like this
    Code (CSharp):
    1.  
    2. void LateUpdate()
    3. {
    4. ....
    5.     Transform transform = animator.GetBoneTransform(HumanBodyBones.Neck);
    6.     transform.rotation = myNewRotationQ;
    7. }
    8.  
     
  5. Maguelonne19

    Maguelonne19

    Joined:
    Jan 29, 2015
    Posts:
    8
    Alright i'll look into that. That's indeed what I read on the forum. Thank you