Search Unity

Preparing blender model for unity

Discussion in 'Asset Importing & Exporting' started by D3adly, Feb 15, 2016.

  1. D3adly

    D3adly

    Joined:
    Oct 5, 2015
    Posts:
    6
    Hi, guys, I am quite new to unity and to blender. Did tons of tutorials, but in the end there is so many and a lot are quite crappy and it got me totaly confused. i have created my character (very basic robot, with animation of moving arms) and imported it in to unity. What i got was not what i expected, my model parts were separated, materials did not import (that one i fugured out, unity does not understand cycles materials). and my animations were wrong... My question would be - how should a blender model be prepared for unity:
    1) format (.blend or .fbx)
    2) mesh (should all parts be merged or not).
    3) origin of parts (should the origin of parts be at 000 or centered on every part)
    4) reseting transformations (should transformations be reset/applied)
    5) armature (should mesh parts be parented to armature)
    6) animations (should animations be done using armature only or can mesh transform animations be imported as well (those did not import correctly for me))

    I know this is a lot of very basic questions that may seem stupid to many pros, but all the info on the net is very confusing, and in the end this may help more beginners.
     
  2. MV10

    MV10

    Joined:
    Nov 6, 2015
    Posts:
    1,889
  3. Cygon4

    Cygon4

    Joined:
    Sep 17, 2012
    Posts:
    382
    1) Pick what you like. Unity can import .blend if you have Blender installed (it calls Blender to export to FBX behind the scenes). Exporting to FBX yourself can give you a little bit more control (eg. only exporting selected objects in case your .blend file contains bone shape meshes or other stuff you don't want exported).

    2) You don't have to merge. If meshes share the same material and it makes sense to merge them, by all means, do so. Each separate mesh and each material means 1 more draw call, which can be a concern on mobile devices or if you have a lot of instances of a mesh.

    3) and 4) Depends on your model. The origin will be imported into Unity exactly as it was in Blender - either baked into the vertex coordinates or stored in the transformation matrix for the object (GameObject in Unity). I usually pivot characters to the ground at 0,0,0 by applying location, rotation and scale. If I was to make, eg. a room, I'd move the furniture to its final position without applying.

    5) Yes. Default Blender setup, everything that's animated by an Armature should be a child of the Armature. Also have all vertices assigned to at least one vertex group. Have a root bone that's the parent of all other bones.

    6) You got it, the only animations that will work are Armature-based ones. No mesh animations and, sadly, no shape keys. Also, the "Preserve Volume" option (= dual quaternion skinning) does not exist in Unity. Only one Armature per file, the exporter will get confused if there are two Armatures in which bones share the same name.


    It's a bit tricky and some trial & error is involved to avoid the pitfalls, but once you do, you can reliably throw Blender's entirely animation pipeline with modifiers, drivers and scripts at Unity :)
     
    Genalx and _GimbalLock_ like this.
  4. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    910
    6) You CAN actually use Shape Keys. But, you can't use them via Blender's animation system. You create them in Blender, and then in Unity via code you can access the shape keys via the skinned mesh component class. I'm sure you could also set them to animate via Unity's animator as well.
     
    _GimbalLock_ likes this.
  5. Botskiz

    Botskiz

    Joined:
    Feb 9, 2016
    Posts:
    4
    I also spent the last few days figuring out how to import models with a "Generic" animation type and root motion, so I figured I'd share my findings as well. Keep in mind that I figured these things out pretty much by trial and error, since I'm not an expert at either Blender or Unity. So there might be better or easier ways to accomplish the same things. I've also attached a unitypackage with a simple test model in a simple scene. There's no scripting in there, just the blender model and animation controllers.

    As far as the file format is concerned, using .blend files gave me less much less headaches than .fbx exports. With .fbx files, I constantly ended up with wrong scaling and animation issues, so I gave up on finding export settings that actually worked for me and settled with .blend files.

    In contrast to what Cygon4 said in 6) about multiple armatures per file, I've had no issues with them if I keep them parented to a common root. So a hierarchy like this should work just fine for me.
    • (Armature) RootArmature
      • (Bone) Root
      • (Armature) ChildArmatureA
        • (Bone) A
          • (Bone) B
          • (Bone) C
        • (Bone) D
      • (Armature) ChildArmatureB
        • (Bone) E
    Also, rather than preparing the model in Blender, I've actually found the import settings into Unity to be the most trouble. As Cygon4 already said, always have a root bone, and make sure to set it as "Root node" in the import settings. In the example above, this would RootArmature/Root. Make sure that this is actually a "Bone" node in Blender's hierarchy, rather than the whole armature.

    As for the animation clips, contrary to what my intuition told me, I found that the "Root Motion Node" to setting should be left to "<None>", if I want root motion to actually work at all. Then, set all three "Root Transform [...]" > "Based Upon" settings to "Original", otherwise objects tend to move in all the wrong directions. I also always set the "Mask" > "Definition" setting to "Create from this model".

    For the "Mask" > "Transform" checkboxes, I found that only those checkboxes should be checked which represent a "Bone" node in Blender's hierarchy. Otherwise I had problems with some transformations being applied twice. Once through the armature transformations, and then again through the bone. Again in the example above, these would be Root, A, B, C, D and E. It is gerally a good idea to only check bones which are actually going to be affected by the animation.
     

    Attached Files:

    MV10 likes this.
  6. Gordyne

    Gordyne

    Joined:
    Feb 22, 2016
    Posts:
    32
    That's strange, my shape key animations(bone oriented) worked fine in unity when I exported them as FBX.
     
    Ignacii likes this.