Search Unity

Blender attatched weapon does not follow armature in unity

Discussion in 'Animation' started by Intervention, Nov 19, 2014.

  1. Intervention

    Intervention

    Joined:
    Nov 9, 2014
    Posts:
    8
    Hi all, my second post here... I promise that soon I will start helping others as those who have helped myself.

    I have a character model I created in blender. This character model has attached to his hands (via IK constraints) a weapon that is itself an external model (that I imported into the same blender project as my character). I have 3 1-frame animations (aim up, aim down, aim straight) that each work fine in Blender.

    I've imported my blender character and his animations into unity. The gun model appears properly positioned for one of the animations (the starting aim forward animation). I successfully have the character blend between the aimup, aim down and aim forward animations based on an aimangle float I use in my script (his arms/body move like I expect). However, the gun does not follow the character (it does not appear to be attached to the hand bones in unity like it was in blender), instead it just stays put where it started.

    Ideally I will have the gun follow the hands the way it does in blender, and I can have multiple weapon aimup/down/out animations that I will create using blender and switch between using blend trees switching based on the gun type my character has equipped.

    My suspicion is because I'm using unity's free edition, which does not support IK constraints, and that since my gun is attached to my hand bones in blender using IK constraints, will not work properly in blender.
     
  2. Intervention

    Intervention

    Joined:
    Nov 9, 2014
    Posts:
    8
    An update: I've found that there are several components to my gun mesh - all of the ones which are NOT parented to the gun control gone in blender do in fact move with my character as they should. The piece of the gun mesh that does not move is different from the pieces that do move in that it has a 'skinned mesh renderer' instead of a 'mesh renderer' component. This piece has the 'root bone' set to the pelvis, which I also do not understand, as in blender, I parented this part of the mesh to its own bone. Moving this bone in the unity animator does not move this piece of the gun mesh, however.

    I'm not sure what to make of this. Any suggestions? Any details I can provide?
     
  3. medhue

    medhue

    Joined:
    Aug 24, 2014
    Posts:
    176
    I would upload the gun as a different fbx, and then attach the gun to the hand in Unity.
     
    theANMATOR2b likes this.
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I second medhue's suggestion with one addition, I would upload the gun as a different fbx, parent it to an empty game object, and parent the empty game object to the hand. Just in case you need an extra hierarchical point between the gun and the hand for anything.
     
  5. Intervention

    Intervention

    Joined:
    Nov 9, 2014
    Posts:
    8
    Thanks for this! I actually started experimenting with this idea today. I am able to get the animations I want in blender, delete the gun mesh in blender, then import both my animated character and the gun .fbx files separately into unity. The player animations work the way I want - great. However after I got to attach my gun to the players hand, this causes all the parents (up to the top armature level) to no longer deform properly when animating within Unity. For example, I have my right shoulder parenting my upper arm, which parents my lower arm, which parents my hand. I then parent my right hand to the gun, to get the following hierarchy (parents on the left):

    shoulder.r->upperarm.r->lowerarm.r->hand.r->gun.

    Whenever I then select my upperarm.r or lowerarm.r from the higherarchy to tweak their positions, Unity selects the gun mesh (even though I've selected upperarm.r, etc), and then moving the arms/rotating the shoulders etc. cause strange deformations to take place that appear to be based on what the gun is attached to, not the bone chain between the gun and whatever I've selected.
     
  6. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I would suggest editing/tweaking the animations back in blender not in Unity. Unity has animation information on those bones and you are attempting to edit that information. I think that's probably whats causing the odd deformations.
    You really shouldn't have reason to mess with the hierarchy in Unity other than to attach/unattach objects.

    A more experienced Unity guy can jump in here and correct me if I'm mistaken.
     
  7. Intervention

    Intervention

    Joined:
    Nov 9, 2014
    Posts:
    8
    Alright, I'll give that a shot. I'm finding it difficult to get the weapons parented properly (to look right) in Unity after doing my aiming/gun holding animations in blender, which is why I was hoping to edit the aiming/gun holding animations in Unity with the guns attached.

    I'll play around with this some more though and see if I can get a good workflow established.

    Thanks for the responses.
     
  8. medhue

    medhue

    Joined:
    Aug 24, 2014
    Posts:
    176
    Ideally, you want to animate directly on the character you are working with, to get exact placement in animations. Things like bone scaling can really throw an animation off. I don't think Blenders IK actually works in Unity, so that is why you are seeing this strangeness. When I try to move an IK bone in Unity, on a rig I created in Blender, it doesn't move any of the rest of the bones, cause the IK isn't even attached to the rest of the bones.

    What you can do, I think, is just change the FK bone rotations in Unity. Ultimately, I'd just get it right in Blender, cause you might want to use that pose/animation as a starting or ending point for other animations. These are just my thoughts tho.
     
    KATOTAH likes this.