Search Unity

What's the workflow for exporting an animated weapon or attachment?

Discussion in 'Animation' started by Nanako, Mar 21, 2015.

  1. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    so i have my character, and a weapon in hsi hand



    the weapon is a seperate object, and i want to export it seperately. I really don't want to have to stick everything on the character and export it at once.

    They're both rigged to an armature, it has a weapon bone which the hammer is entirely rigged to.

    so i select the hammer, and the armature, and export them, import it into unity, and just drop it into the same heirarchy as my character (they share a parent). I assume the animaiton and rigging should put the hammer in the right place from there, but maybe i'm wrong.

    anyways it doesn't seem to work. The hammer does correctly drop into the desired position for the T pose, but then just sits there floating in midair off to his side, while the rest of the character animates
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Multiple ways to do this. You stated you don't want to put 'everything' on the character and export it at once, but this is an option. Having 10-20 weapons rigged to several bones parented to the hand bone. Hide/unhide mesh & bones as needed.

    Other option is to have the weapon as a separate mesh, rigged to a bone separately, not parented to the hand bone in Blender. Then parent in Unity, and control the weapon with the animation of the characters hand.

    I'm sure there are other ways but these two I'm familiar with.

    I watched a video a while ago of a guy controlling the hands by animating the weapon. He was doing the setup for Unreal so it was a little odd, and the fact he was animating the weapon to control the hands was odd too.
    But it was interesting to see a different approach to 2 handed weapon setup.
     
  3. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    this is not an option. I'm making five different meshes for every weapon, which will probably result in close to 100 weapon models, having them all within the same fbx is not going to work.

    What exactly do you mean "not parented to the hand bone" are you referring to the mesh, or to the weapon bone?


    check my OP, the hammer up there is parented to the armature, but not under any specific bone, it has weiofght for the weapon bone.

    The weapon bone is hard to see above because i made a custom bone shape for it to match the shape of the hammer. This might help:



    This is just the armature.


    So far i've not gotten this setup working in unity, and i'm not sure why. There are a couple of points of ambiguity,. such as the avatar. Do i generate one, or copy from the actor's one?
    Where in the unity object hierarchy do i place the weapon? on the same level as the actor ? (i have them both under a parent/container object atm)

    basically, just help me get a proof of concept working so that i can:
    1. Export the actor without the hammer mesh
    2. Export the hammer mesh without the actor mesh
    3. Make these two work and animate correctly in unity
     
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    It might not be an option for your specific setup, but it's still an option. 5 meshes for every weapon? That's a unique idea. Is the concept something like adding parts to each weapon to make them look meaner/stronger? Have you considered mesh occlusion masking? If not - look it up, that may be an alternate approach to making 5 separate mesh pieces per weapon.

    Sorry I don't know what the armature is in blender? Is that the rig?

    My suggestion is to rig and skin weight the weapon to one bone, not parented to anything else. Treat it as a unique asset with a unique import into Unity. When you get your character into Unity orient the weapon bone to the hand bone and parent the weapon bone to the hand bone. Then you don't have to mess with animating the weapon. The hand controls the weapon.
    Just like if you created a box, parented a cylinder to the box, animated the cylinder rotating as the box moves around and bounces up and down. Then import the box and cylinder into Unity as one. This is the character, the cylinder is the arm of the character. Parent another cylinder to the animated cylinder. Now the second cylinder moves with the animated cylinder. i.e. the weapon follows the animation of the hand/arm.

    This is a good troubleshooting exercise. Do 1 if it doesn't work, do 2. If 2 doesn't work do 3.

    The additional questions you asked about the avatar and actor in your last post I'm not addressing because the original question hasn't been solved yet. I think it's best to solve one issue at a time so there isn't confusion.
     
  5. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    No it's not. Sounds like someone hasn't played many games. I'm ripping the idea directly from Ratchet and Clank. I'm happy with the way i'm planning things and i don't see any conceptual problems.


    You're an animator, and you've never heard that word?
    http://en.wikipedia.org/wiki/Armature_(sculpture)

    It's the skeleton. The thing which has the bones in it. Bones are those things you move to deform the overlying mesh

    Why would i do that IN unity? I'm already doing it in blender, which is far more flexible, and allows me to move the weapon around relative to the hand as i please. Sledgehammers are a weapon that tends to slide up and down the haft from a stance to a swing.

    The weapon bone is already parented to the hand bone, i think i said that. Making them two seperate armatures and parenting within unity seems like a nonsensical idea.

    So just to be clear:

    I have one armature, in total
    It has all the bones in it, including the upperarm, lower arm, hand, and weapon bone (parented in that order)

    I export it, and the actor mesh. They work fine in unity.

    I export it, and the sledgehammer mesh. What do i do with this in unity? Where does it go. Simply having it as a child of the object containing the animator controller doesnt seem to be working.
     
  6. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I don't see a problem with your concept though being closed to alternative approaches to solve a problem has negative consequences eventually. When I said its a unique idea I meant it as a compliment. It's an interesting idea.
    Reread my last post regarding 5 meshes per weapon, which could be an alternative approach to 5 separate meshes per weapon.

    Blender tends to use different definitions for established conventional things. The common word for what you are calling an armature is called an animation rig or just rig. Rigs consist of bones, animation controls, and software specific animation tools.

    Because attempting an alternate approach reduces the theoretical reasons things aren't working correctly. And it troubleshoots the problem you stated in your first post by approaching the problem differently.
    Having a weapon and bone independent from the character is an alternate and proper workflow.
    What happens when your character drops the weapon, or dies? It can't be un-parented if it's not a separate "armature" as far as I know. I'm not a code guy so it may be possible with code, but that seems like, kind of a backwards way to do things. Parenting in the authoring tool, only to need to unparent it in code later.

    Some friendly advice - It's not a good idea to ask for help then tell the person who's attempting to help - there ideas are nonsensical.
    I offered logical workflow suggestions because I've set up characters with weapons in the exact process I've described and didn't encounter the issues you are having. So the process may seem nonsensical but it works correctly.


    Good luck with your characters. Hope you find answers to the numerous questions you still have.
     
  7. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    No its perfectly normal. Then the weapon would simply be removed from the animator's sphere of influence (unparented from the container object i guess) and given a rigidbody +gravity to let it be a free object. there aren't any issues at all.

    For some reason, i actually thought you would say this. Apologies if i've offended you. I'm not looking for alternate ways around the problem, i'm looking to clear the path through the problem. A path which should already be clear, and makes no logical sense as to why it's not working.

    I don't see how your suggestion of a second armature can work, and still allow flexibility in animating. The character and the weapon need to be animated in sync, and i don't see how i could do that in blender if i had to keep switching back and forth.

    Certainly it makes sense for a weapon to have its own armature for "internal" animations. Eg, moving parts, but the main movement seems most logical as parented to a single bone of the main armature.
     
  8. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I went back and re-read how the setup currently is and I actually see how this setup can be helpful for having an animated weapon.
    When you say "just drop it into the same hierarchy as the character (they share a parent)" does that mean the weapon mesh is getting directly parented to the weapon bone that is in the character armature?
    This may be where it is failing if the weapon mesh isn't getting parented directly to the weapon control bone.

    To clarify (they share the same parent) - is this master parent an empty game object you use for locomotion?

    It needs to be further down in the hierarchy - at the weapon bone level.
    upload_2015-3-24_12-12-15.png
    I'm at work :oops: so the only example I have is the standard asset construction worker.
    The wrench is parented directly to the right hand bone, but I'm unsure if the wrench was imported with the character model and rig or as a separate mesh - then parented in Unity.
    Switching the construction worker to a humanoid rig doesn't break the animations. The wrench stays in the hand even after changing the rig. There isn't a bone for the wrench, the separate mesh is simply parented to the hand bone.

    And this leads into your other questions regarding the avatar setup. :)
     
  9. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
  10. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    this is not rigging. This is a cheap workaround that successfully solves that particular problem, only because a wrench (and many similar weapons) are rigid and don't need to move with multiple bones.

    Lets try a completely different topic.

    Say my character was going to wear this piece of armour




    Random picture pulled off google. But assume i had an armour like this, it's all one single mesh, and it cannot be broken up.

    That needs to be rigged to the armature properly so that it bends at the spine, the shoulders, and the elbows, while still holding together as one object. Assume i've done that rigging and bone weighting, and it works perfectly within blender.. It's being exported as a seperate fbx from the character.

    Now how do i put that onto my character in unity, so that the rigging works correctly.
     
  11. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    from lots of searching around, it's sounding like i have to either combine the meshes into one, or use multiple copies of the animator to achieve what i need. why is this so complicated

    what about submeshes. Is that a thing? can i use those?

    And what then, is the situation where i export both actor and weapon in the same fbx (but still as seperate objects). Then they only have one armature between them, yet one seems to work and one does not
     
  12. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    Is it the case that an animator can only animate one mesh at a time, or can it animate several?

    What determines which mesh(es) are animated? The avatar, presumably ?
     
  13. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    Well this thread really was not helpful. @theANIMATOR2b i really appreciate your trying to help, but i suspect you didn't know what i needed in the first place.

    I've found a solution: http://forum.unity3d.com/threads/stitch-multiple-body-parts-into-one-character.16485/

    The general gist is, skinned meshes reference their armature not just by bone names, but also by pointers. And so if i import a character and a piece of armour seperately, both of their animation datas are essentially referencing different instances of the same skeleton, and thusly animating one skeleton will not cause both items to deform properly.

    The solution, then, is to first designate a single mesh as the root/host/core/whatever. And then to alter the SkinnedMeshRenderers of the other (sub-objects) in order to completely replace their bone list with the bones from the root object, thusly both meshes will then actually reference the same skeleton, and can both be animated by playing animations on that.

    That's the theory anyways, haven't quite got it working yet.

    The advantage of thios method it seems, is that it's not required to actually fuse the meshes together, they can remain seperate objects, just sharing animation data, as originally desired.
     
  14. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Yeah I've read that thread several times but never implemented it on personal work.
    I've created a couple characters that switch load outs at run-time but I've not worked on the 'code' side to get the setup working in Unity.
    Since I'm an animator, not a programmer, I personally would set this up in Max with one base naked character rig.
    Create clothing sets for the character and export the complete model with polys removed below the clothing.
    Swap the complete character at run-time within Unity.
    Max has a skin wrap modifier which allows clothing or other accessories to be wrapped on top of a previously rigged and skinned character. This modifier reduces the amount of skinning/rigging work required drastically, and can be converted to a skin for exporting into Unity.

    That's how I'd do it for my own characters that need different outfits. I worked on a contract last year that used the same setup the mixamo fuse editor uses (occlusion mesh masking). That combined with skin wrap modifier was sufficient for the team to get swappable clothing system working as they needed.
     
  15. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    Can you clarify this? i'm very interested in removing occluded geometry, but a runtime
     
  16. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    No I cant since I was only involved with rigging and animation tasks.
    I was told this was how they were accomplishing runtime occlusion and they referenced the fuse info on mixamos site.
    Though fuse was not used for character model development.

    This seems to be a closely held solution - not shared by those who know the proper setup process.
    It may be possible to learn the process via mixamo/fuse research, since the fuse clothing creation tutorial suggests creating the occlusion mask map - but I have not had time to do the leg work on this.

    I suspect (because I have zero experience with shaders) it has something to do with shader setup. :)

    Possibly applying the occlusion mask map to the opacity map slot of the base body mesh at run time (tied to the clothing loadout somehow) would occlude the underlying body mesh under the clothing.
    That sounds like a workable process but there would need to be an occlusion mask map for every clothing loadout possible. A lot would be similar like pants mask for all different pants parts etc.