Search Unity

Mécanim and characterization using c#

Discussion in 'Scripting' started by covert, Dec 3, 2012.

  1. covert

    covert

    Joined:
    Nov 29, 2012
    Posts:
    16
    Hey guys,

    Any way to change the bone mapping of an avatar via script?
    I am seeing Animator.GetBoneTransform(), but no 'set' method.

    Also, is it possible to grab the avatar that is created when importing an asset?
    I only see documentation on how to access an avatar that is attached to to an animator.

    Thanks,
    Kim.
     
  2. Landern

    Landern

    Joined:
    Dec 21, 2008
    Posts:
    354
    Hey Kim,

    You may want to try and change the Transform that is returned from calling GetBoneTransform(). If this is an object by reference(it smells like it is), then changing the properties of the Transform from the GetBoneTransform() call will be reflected because it is a reference not a deep copy/clone of the object.
     
  3. covert

    covert

    Joined:
    Nov 29, 2012
    Posts:
    16
  4. Landern

    Landern

    Joined:
    Dec 21, 2008
    Posts:
    354
    I'm assuming that the reference from the GetBoneTransform function/method is good enough. But i'm only guessing, so the returned Transform type from calling GetBoneTransform, any manipulation of the object is live... You are getting a direct reference to the transform that you show in you image, if there is one to return.

    Code (csharp):
    1.  
    2. ....
    3. Transform myHip = Animator.GetBoneTransform(HumanBodyBones.Hips);
    4. myHip.Position = Vector3.zero; // 0, 0, 0
    5. ....
    6.  
    So i changed the position by getting the transform from the GetBoneTransform call, but the returned Transform was a reference, any direct manipulation directly affects the bone transform, no set needed. But this is a guess and i'm guessing because it doesn't have an explicit set method/function.
     
  5. covert

    covert

    Joined:
    Nov 29, 2012
    Posts:
    16
    I am not trying to set the translate/rotate/scale values of those transforms.
    I want to change the references; to have them point to other transforms.

    e.g.:
    Image shows a reference to 'l_thumb1', 'l_thumb2' and 'l_thumb3'.
    Script should set them to 'l_thumb0', 'l_thumb1' and 'l_thumb2'.