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 are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    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

    Unity Technologies

    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

    Unity Technologies

    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
     
unityunity