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

Complex GameObject/Bone attachment issue Hat -> Hair -> Player

Discussion in 'Animation' started by joedurb, May 27, 2014.

  1. joedurb

    joedurb

    Joined:
    Nov 13, 2013
    Posts:
    38
    EDIT: Workaround posted below

    Attaching Rigged Animated objects so they move together works really well, (via Legacy Anim system), Using the code (snippet):

    var newBones:Transform[] = new Transform[ WearMesh.bones.Length ];
    for ( var i:int=0; i<WearMesh.bones.Length; i++ )
    newBones = FindTransform(Player.transform,WearMesh.bones.name);


    Works great for say a hair mesh attaching to the Head and moving with the animations of a player object.

    Now, because Hair offsets a hat differently based on Hair types (affro vs bald) I figured I would simply attach Hair to Player,
    Then attach Hat to the Hair. While I have managed to get positioning to work, Animation does not come through.

    I have also tried attaching the Hat to the hair, then Attaching the combination to player. No animated movements.

    Details:
    Player Model has a Hat Bone. (For baldy) When no Hair, Just attach Hat to Player.Hat Bone, and all is well.

    Hair has a Hat bone as well, And then this Object is attached to player, the hair moves and positions perfectly.

    But now, This "Hat" Bone on the Hair, Receives no animation at all If I attach A Hat to it.

    Struggling with alternative ways to achieve the result. and failing so far.

    Thanks much if anyone has some deeper understanding of the mechanics at play here!
     
    Last edited: May 27, 2014
  2. joedurb

    joedurb

    Joined:
    Nov 13, 2013
    Posts:
    38
    I stopped trying to "Wear" the hat, and just stick it at a mount point.

    I just computed the offset between The normal head Hat point, and the Hair's Alternativ Hat point, And adjusted the hat by that offset, yet still parenting it to the player hat point so that the animation carried through.

    example code fragment:
    T=FindTransform(playerObject.transform,"Hat");
    T2=FindTransform(playerObject.transform,"HairHat"); //alternative hat point set within hair (which is already parented to player)
    if (T2!=null) { //If hair has a hairhat position, offset hat by the diff
    hatOffset=T2.position-T.position;
    }
    //Attach the hat statically rather than animatedly
    clothing.transform.position=T.position;
    clothing.transform.position+=hatOffset;
    clothing.transform.parent=T;

    So, it works. I would still prefer to be able to attach an object to bones of previously attached objects, but I guess unity Does not "Animate" those relative bones since they are not a part of the original Animation.