How to Export Models from Blender to Unity

Preface

Skill Requirements:

  • Basic knowledge of Blender

Tutorial was made with:

  • Blender 2.92

Difficulty: Beginner

In this tutorial, we will learn how to correctly export FBX models from Blender to Unity, once and for all. For starters, here are the showcases of the results we will achieve by following this tutorial:

The result for the FBX method:

Model export using FBX files

The result for the .blend method:

Model export using the .blend in Unity

Don’t have time to read a bunch of well-written, high-quality prose? Click the button below to go to the steps.

You will miss a lot of good information though, so make sure to come back later and read it when you have a minute.

Introduction

If you’ve ever had the pleasure of working in Blender-to-Unity pipeline, you will most likely have had weird behaviors in Unity after importing a model from Blender. Chances are that the following will feel familiar to you:

  • Objects in Unity face backwards.
  • Object Transforms have weird rotation values such as -90 on the X axis, 180 or -180 on the Y or Z axis.
  • Objects are either way too big, or way too small, with the Transform Scale values being not uniform (1, 1, 1).

So what did you most likely do in those situations? You either:

  • Used the model as is.
  • Positioned the model correctly in the scene view, slapped it inside an empty GameObject, created a prefab out of it, and called it a day.
  • Turned to Google to look for the “correct way” to export models to Unity.

The first option works great at first since you don’t have to do anything extra. You have your model and you’re enjoying the fruits of your hard labor. But the joy appears to be short-lived when you try to manipulate the object’s Transform in code. You use Transform.forward to move the object but your model, instead of strutting forward, suddenly moonwalks backwards. Okay, no big deal. You can fix this using the second option.

The second option, indeed, fixes the problem seen with the first method, and is a viable solution. However, it requires manual object placement into the correct orientation first and wrapping it inside another GameObject. You could automate this by spawning the model inside an empty GameObject and adjusting its transform accordingly in code. But this is bug-prone and hard to consistently achieve good results. Your GameObject factory will not be able to tell dynamically how to orient the object correctly, since every object may be exported from Blender with different transform values. This can happen if, for example, different artists contribute to your asset pool, or simply by accident. You come to the conclusion that the second option does not fit your workflow and you turn to option three.

Unless you have created your own FBX export pipeline by modifying Blender’s FBX exporter and creating custom asset postprocessors in Unity, you failed to find a complete answer on Google, as it was simply not possible to achieve perfect results without putting in elbow grease. That was until recently. In this tutorial, we will see how to easily export models to Unity in a proper way, which face correct forward direction (or any direction you want that you specify in Blender) with all their transforms at perfect values.

FBX vs .blend

There are two main ways to get your Blender models to appear in Unity:

  • Export models as FBX files and copy them to Unity.
  • Store the whole .blend file in Unity directory and let Unity handle all the hard work.

In this tutorial, we will cover both cases. As to which exporting method is better and which you should use, it’s up to you for now (we will explore this topic in a future post). I like to keep my source files separate from the production assets so I export to FBX first.

We will handle the exporting to FBX case first, and then the .blend case later at the end of this tutorial.

Setting Correct Axes

Before we dive head first into this, we need to correctly define the transform axes we will be using because Blender and Unity use different axes for their FORWARD and UP directions.

Unity uses:

  • +Z as the FORWARD axis
  • +Y as the UP axis

Blender, on the other hand, uses:

  • +/-Y as the FORWARD axis
  • +Z as the UP axis
So, is the FORWARD axis +Y or -Y in Blender?

As far as I know, Blender doesn’t have the forward axis defined as either +Y or -Y. Forward axis in Blender is simply “along the Y axis.” From the way Blender’s “flagship” mesh object — monkey Suzanne, is oriented when adding her to the scene, we can infer that the forward axis should be -Y, since Suzanne faces in the -Y direction and if she were to move in this direction, the most accurate way to describe this change of location would be as “moving forward.”

Relevant to the topic of FBX export: when exporting FBX, if the Forward axis is set to -Y, the exporter expects the +Y as the forward axis and will apply a rotation of 180 degrees on the Z axis to the root object so that it’s facing in the +Y direction.

To account for the difference, we need to tell Blender which axes we want the FBX exporter to write to the file as being the object’s UP and FORWARD axes. But which do we define as which?

Defining the Forward Axis

Let’s assume that the front view in Blender is defined as observing from the -Y axis towards the +Y (facing the +Y axis). If we look at out beloved monkey Suzanne in the image below, we’ll see that she’s facing the -Y direction. If Suzanne were to start walking (or rather floating?) forward, she would move in the same -Y direction. Objects usually move forward with their front and we want them to be oriented that way, therefore our FORWARD axis is -Y.

Blender's monkey Suzanne with named axes

Defining the Up Axis

Up axis is the direction Suzanne would move if she were to jump, which is the +Z axis.

When exporting, we will use -Y as the FORWARD axis and +Z as the UP axis.

How Blender Exports FBX

Let’s say we have a hierarchy of 5 parented objects with all their transforms reset.

If we export them with the default FBX exporter settings, we will get the following Transform values in Unity:

The root object:

  • Position: same as in Blender
  • Rotation: X -89.98
  • Scale (100, 100, 100)

The root object children:

  • Position: same as in Blender
  • Rotation: (0, 0, 0)
  • Scale: (1, 1, 1)

All children have the values we want but the root object does not. We want all rotation values be at 0 degrees and all scale values at 1. Let’s investigate how we can fix the parent. We’ll start from the easiest and move on to the hardest.

Fixing Scale

This one is pretty straightforward. Set the Apply Scalings option to FBX All in the Transform section of the FBX exporter panel and you’ll never have to worry about it again.

Apply Scalings is set to FBX All

Re-export the model and you’ll see that the scale is now (1, 1, 1).

Fixing Position

With regard to position, this is not the case of Blender doing something wrong. Unlike with rotation, It does exactly what you expect it to do and exports the model at whatever position you have it set at. However, we often want to have the model exported with its root object at the world origin (0, 0, 0). To do this, we can select the object we want to move to the world origin and press ALT + G .

Fixing Rotation

Now, this one is the mother of all that is painful. If the model you’re exporting is a static mesh, i.e. not rigged and animated, then it is a little bit less of a pain than it is when you’re dealing with a rigged mesh. The moment you want to move bones in specific ways in Unity via manipulating their Transforms in code, you WILL get unexpected behavior that you really don’t want to have. So, how can we spare ourselves the agony and make sure that the rotations are correct in Unity? For completeness sake, we will discuss the old methods of exporting first, and leave the best one for the end. Let’s see:

Apply Transform

The easiest solution probably everyone has tried at least once is to use the Apply Transform option.

Apply Transform export option

Often times, it seems to fix the problem. However, there is a triangle with a question mark icon next to its name and a tooltip warning us that the option is experimental. Nonetheless, it sounds from the description that it does what we want, and it sort of does, but not without consequences:

  • If the mesh is rigged or animated, this option will break those (what broke may or may not be apparent at first).
  • If the object’s hierarchy is larger than 2, objects at depth 3 in the hierarchy and beyond will still have incorrect transform values. This is a problem if you’re building a complex object that requires deep and sophisticated parent-child relationships. When you try to manipulate their transforms in Unity via code, you WILL get erroneous results, such as things moving and rotating in a weird fashion.
I’ve been using Apply Transform export option without any issues, even with rigged meshes.

It was most likely because your meshes didn’t have complex parent-child relationships, or you didn’t manipulate bone transforms in code.

See these issues with examples of what kind of problems you can run into by using this option:

https://developer.blender.org/T43352

https://developer.blender.org/T70799

https://developer.blender.org/T65478

https://developer.blender.org/T50405

Can’t I export the parts of the complex objects un-paranted and then parent them in Unity?

I guess but there is a better way.

It’s sort of like being a 3D artist who does sculpting for a living and whose drawing tablet suddenly dies, but they decide to just work with the mouse for the rest of their career instead of getting a replacement. Why cripple yourself when a perfect solution to the problem is available?

When Is It Safe to Use Apply Transform?

In summary, Apply Transform should never be used as there is a different easy and perfect solution for exporting. However, if you insist, it can be a viable solution only in the following cases:

  • Mesh is static (not rigged or animated).
  • Object hierarchy is not deeper than 2 levels.

Pre-Rotate Object

If your object is rigged, the following steps will result in correct transform values in Unity:

  1. Set armature rotation to -90 degrees on the X axis.
  2. Apply Rotation by pressing CTRL + A > Rotation.
  3. Rotate the armature by 90 degrees on the X axis.
  4. Select all children objects of the armature and Apply Rotation.
    • This is necessary because when Applying Rotation, Location, or Scale Blender sets that transform value to all object’s immediate children. By selecting all children first and applying their transforms we save ourselves some time and sanity by avoiding applying transforms in one by one.

After going through these steps, the objects appear to have correct transform values in Unity. However, the 3rd object in the hierarchy displays -89.98 rotation on the X axis while all the other ones are correct (tested up to 5 levels deep). I’m not sure what causes this, but it is peculiar.

When Is It Safe to Use Pre-Rotate Object?

In summary, Pre-Rotating object should never be used as there is a different easy and perfect solution for exporting. However, if you insist, it can be a viable solution only in the following cases:

  • Mesh is static or skinned (rigged or animated).
  • Object hierarchy is not deeper than 2 levels.

Uncheck Use Space Transform — The Best Way

This is a new option that is available starting from Blender 2.92.

Use Space Transform export option in Blender FBX exporter
Use Space Transform option

This option was added to Blender source as far back as June 2020 but only now has found its way into the core Blender release. Even though this option didn’t exists in the way it is defined now, under the hood, its functionality has always been “enabled” meaning that, just as the description in the image above says, Blender has always applied global space transform to every object before exporting.

How can we leverage this option in our Quest of Perfect Transforms in Unity? Simply uncheck this option and export away.

This is not the end, though. If you import your exports in Unity, you’ll be disappointed to see something like this in your object inspector:

Rotation values should be zero but they’re not

This is where the final piece of the puzzle comes into play. Select your imported model in the Project view and tick the Bake Axis Conversion checkbox in the model importer inspector window. This is a recent option introduced in Unity 2020.1 and together with Blender’s Use Space Transform option disabled, marks the end to the utter confusion and torment that was plaguing the community for over a decade.

Step by Step Instructions on How to Properly Export Models from Blender to Unity as FBX

Make the following changes to the default settings:

  • In Blender:
    1. Make sure the object Transform values are set to the following (unless you have a specific reason to keep these values custom):
      • Location: (0, 0, 0)
      • Rotation: (0, 0, 0)
      • Scale: 1, 1, 1
    2. In the FBX exporter panel, set the following settings:
      • Apply Scalings: FBX All
      • Forward: -Y Forward
      • Up: Z Up
      • Use Space Transform: unchecked
  • In Unity:
    1. In the Model Importer Inspector window:
      • Bake Axis Conversion: checked
Location, Rotation, and Scale values should be as displayed in most cases.
Blender FBX exporter Transform panel settings for perfect model export to Unity
Bake Axis Conversion option in Model Importer Inspector window in Unity

Step by Step Instructions on How to Properly Export Models from Blender to Unity using .blend

NOTE: When using this method, the Use Space Transform and Forward/Up settings in the FBX exporter panel won’t have any effects when exporting FBX files. Instead of the entered values, the exporter will use the values we hard-code into the __init__.py file below.

  • In Blender:
    • Make the following modifications to __init__.py file located at C:\Program Files\Blender Foundation\Blender 2.92\2.92\scripts\addons\io_scene_fbx
      • Set global_matrix = Matrix() at line 631
      • Several lines down, above the line keywords["global_matrix"] = global_matrix, add the following two lines:
        • keywords["axis_forward"] = '-Y'
        • keywords["axis_up"] = 'Z'
Modifications to Blender’s FBX exporter file
  • In Unity:
    • In the Model Importer Inspector window:
      • Bake Axis Conversion: checked
Bake Axis Conversion option in Model Importer Inspector window in Unity

Having Fun with Forward and Up Axes

And finally, if you haven’t modified the __init__.py file, the Forward and Up axes in Blender’s exporter now work correctly. You can set them up in Blender according to what orientation your model faces, and the model will still be oriented correctly in unity. Let’s take a look at an example.

Say, for whatever reason, you decided to model an object like in this picture:

Model in the picture was created by 3DMaesen

By following the outlined steps above, we can have a perfect result in Unity. All we need to do is set the correct Forward and Up axes in Blender FBX exporter. In the image above, our model is facing the +Y direction and its head is pointing in the -X direction, therefore, we need to set the Forward axis to +Y, and Up axis to -X, like this:

We hit Export, open up Unity, check the Bake Axis Conversion toggle and admire the results:

Model is perfectly oriented in Unity despite funny orientation in Blender

Conclusion

There we go. Let’s enjoy our newly found power to the fullest.

Did you like it? Please consider the following to help me make more great content for you:

Was this helpful? Have a question?

Please leave me feedback by filling out the form bellow. It means a lot to me: