Search Unity

Adding bone to FBX and to its prefabs / Better way to add gun-blast FX?

Discussion in 'Animation' started by SpencerPDX, Mar 11, 2014.

  1. SpencerPDX

    SpencerPDX

    Joined:
    Jan 3, 2012
    Posts:
    168
    Hello!

    I'm running into an issue trying to add a bone to an FBX character after having already imported it and used it to create various prefabs. I've researched it as best I could, and from what I can tell the problem is one of getting the prefabs to update with the additions to the FBX rig. Just not sure how to do that.

    It's for this character:




    Grunt Robot for Flarb LLC

    It starts in 3ds Max as a character with a lot of swappable parts: arms, guns, swords, etc. They are all rigged to a single skeleton. The different variations are then given different color materials:



    When I go to export (and this may not be the right way, but it worked for me) I select all the meshes and export them as the base mesh. And then I also export them that way for the various animations, such as attack_gun.fbx, idle_nuance.fbx, that sort of thing. (That's been working fine, though it has always seemed odd to me in using Unity that it works best to export the mesh and not the skeleton. But I guess the skeleton gets exported via the vertex weighting.)

    Anyway, the problem I ran into came about when the client asked me to add a bone (or some kind of node he could use) to then end of the gun, to mark the point at which FX will shoot out. The rig is a Max Biped, but I've added extra bones to it in the form of dummy objects to this rig, for things like ears and eye blinks. I know dummy-as-bone is a reliable approach, so I added the FX bone in the same way.



    When I look in the new FBX in Unity, I can see the FX bone in its hierarchy.



    But there's a bunch of prefabs in the project, and I'm not seeing the bone appear in the prefabs. Even when I delete an existing prefab from the scene and replace it with one from the project.



    This is problematic because I put a fair amount of work setting up new shaders for those prefabs and would rather not do that work all over again!

    And I get errors like this:

    Code (csharp):
    1. [mecanim]: BindSkeleton: cannot find Transform 'Bip001 gun_beam'
    2.  
    In setting this character up I configured the FBX Avatar to use extra bones, and like I said, the other non-Mecanim bones like ears and eyelids are there, and they import correctly.

    It's just the new bones aren't making it into the prefabs.

    TL;DR: There are two basic questions here:

    1) Is there any good way to add a bone to a rigged FBX character such that that change will be incorporated into prefabs made from that FBX?

    2) Are there better ways to add nodes for emitting FX?

    Thanks for any help!
     
    DChap likes this.
  2. OllyNicholson

    OllyNicholson

    Unity Technologies

    Joined:
    Jun 17, 2011
    Posts:
    142
    1)

    Prefabs are by nature 'prefabricated' so if you change the hierarchy of the asset within the prefab then you need to create a new prefab. Fortunately you can update all your prefabs using this common workflow:

    1 Drag your existing prefab into an empty scene
    2 Export your new FBX file over the old one
    3 Delete the FBX model node under the prefab Parent node
    4 Drag the re-imported FBX in to the hierarchy, and then onto the Prefab parent node
    5 Now drag the new prefab in your scene (now containing new bone) over the prefab in your project file to update it (and all) instantiated prefabs

    This relies on the common practice of having an empty parent node (e.g. character controller) with all relevant scripts applied and the FBX container node as a child. If you have not used this workflow first time round for your characters (e.g. applied your scripts to the FBX container node) then the workaround would be:

    1 Drag your prefab into an empty scene hierarchy
    2 Create an empty node at 0,0,0, name it as your Character or such like
    3 Make note of the scripts and parameters of the FBX container node and re-apply to the parent instead
    Repeat steps 4 and 5 from above

    If you wish to export a new file with which to update your prefab (with new hierarchy) rather than on over the existing FBX make sure you set scale in the importer and use 'by Material name' to pick up the same existing materials.

    2)

    You can simply attach child nodes in Unity (emitters, objects) to the bones in the hierarchy and update your prefabs as with step 5
     
    Last edited: Mar 12, 2014
    DChap, martinfitzjerl and dark_tonic like this.
  3. SpencerPDX

    SpencerPDX

    Joined:
    Jan 3, 2012
    Posts:
    168
    Olly thanks so much for this reply, it helped a ton. Your option #1 gave me a better sense of the workings of prefabs, which have always seemed a little mysterious to me, and your option #2 made me slap myself on the forehead with great force. Why didn't I think of that? It did the trick.