Meshes
At the core of any 3D game are Meshes - objects consisting of triangles, with textures applied.
Meshes in Unity are rendered with renderer components. Although there may be many variations, a Mesh Renderer is the most commonly used.
- The renderer displays the mesh at the GameObject's position.
- The appearance of the mesh is controlled through the renderer's Materials.
Meshes
Meshes make up a large part of your 3D worlds. Unity doesn't have its own tools for mesh creation but has good interactivity with popular 3D modelling software. Importing meshes is mostly straightforward but the following pages note things that you need to watch out for with particular applications.
Other applications
Unity can read .FBX, .dae (Collada), .3DS, .dxf and .obj files, so any software that that can export any of these formats should work fine with Unity. FBX exporters for popular 3D packages can be found here. Many packages also have a Collada exporter available.
Textures
Unity will attempt to find the textures used by a mesh automatically on import by following a specific search plan. First, the importer will look for a sub-folder called Textures within the same folder as the mesh or in any parent folder. If this fails, an exhaustive search of all textures in the project will be carried out. Although slightly slower, the main disadvantage of the exhaustive search is that there could be two or more textures in the project with the same name. In this case, it is not guaranteed that the right one will be found.
Place your textures in a folder at or above the asset's level
Import settings.
The Import Settings for a mesh file will be displayed in the inspector when the mesh is selected.
The Mesh Import Settings dialog
Meshes | |
Scale Factor | Unity's physics system expects 1 meter in the game world to be 1 unit in the imported file. If you prefer to model at a different scale then you can compensate for it here. |
Use File Units | This option is available only for 3dsMax files. If enabled it imports 3dsMax file with one Max unit equal to one Unity unit, otherwise it imports with 1 cm equal to 1 Unity unit. |
Mesh Compression | Increasing this value will reduce the file size of the mesh, but might introduce irregularities. It's best to turn it up as high as possible without the mesh looking too different from the uncompressed version. This is useful for optimizing game size. |
Mesh Optimization | This option determines the order in which triangles will be listed in the mesh. |
Generate Colliders | If this is enabled, your meshes will be imported with Mesh Colliders automatically attached. This is useful for quickly generating a collision mesh for environment geometry, but should be avoided for geometry you will be moving. For more info see Colliders below. |
Swap UVs | Use this if lightmapped objects pick up the wrong UV channels. This will swap your primary and secondary UV channels. |
Generate Lightmap UVs | Use this to create the second UV channel to be used for Lightmapping. |
Advanced Options | See Lightmapping UVs document. |
Normals & Tangents | |
Normals | Defines if and how normals should be calculated. This is useful for optimizing game size. |
Import | Default option. Imports normals from the file. |
Calculate | Calculates normals based on Smoothing angle. If selected, the Smoothing Angle becomes enabled. |
None | Disables normals. Use this option if the mesh is neither normal mapped nor affected by realtime lighting. |
Tangents | Defines if and how tangents and binormals should be calculated. This is useful for optimizing game size. |
Import | Imports tangents and binormals from the file. This option is available only for FBX, Maya and 3dsMax files and only when normals are imported from the file. |
Calculate | Default option. Calculates tangents and binormals. This option is available only when normals are either imported or calculated. |
None | Disables tangents and binormals. The mesh will have no Tangents, so won't work with normal-mapped shaders. |
Smoothing Angle | Sets how sharp an edge has to be in order to be treated as a hard edge. It is also used to split normal map tangents. |
Split Tangents | Enable this if normal map lighting is broken by seams on your mesh. This usually only applies to characters. |
Materials | |
Import Materials | Disable this if you don't want materials to be generated. Default-Diffuse material will be used instead. |
Material Naming | Controls how Unity materials are named: |
<textureName>.mat | The name of the diffuse texture of the imported material that will be used to name the material in Unity. When a diffuse texture is not assigned to the material, Unity will use the name of the imported material. |
<materialName>.mat | The name of the imported material will be used for naming the Unity material. |
<modelFileName>-<materialName>.mat | The name of the model file in combination with the name of the imported material will be used for naming the Unity material. |
<textureName>.mat or <modelFileName>-<materialName>.mat (OBSOLETE) | The name of the diffuse texture of the imported material will be used for naming the Unity material. When a diffuse texture is not assigned or it cannot be located in one of the Textures folders, then the material will be named <modelFileName>-<materialName>.mat instead. This option is backwards compatible with the behavior of Unity 3.4 (and earlier versions). We recommend using <textureName>.mat, because it is less complicated and has more consistent behavior. |
Material Search | Controls where Unity will try to locate existing materials using the name defined by the Material Naming option: |
Local | Unity will try to find existing materials only in the "local" Materials folder, ie, the Materials subfolder which is the same folder as the model file. |
Recursive-Up | Unity will try to find existing materials in all Materials subfolders in all parent folders up to the Assets folder. |
Everywhere | Unity will try to find existing materials in all Unity project folders. |
Animations | |
Generation | Controls how animations are imported: |
Don't Import | No animation or skinning is imported. |
Store in Original Roots | Animations are stored in the root objects of your animation package (these might be different from the root objects in Unity). |
Store in Nodes | Animations are stored together with the objects they animate. Use this when you have a complex animation setup and want full scripting control. |
Store in Root | Animations are stored in the scene's transform root objects. Use this when animating anything that has a hierarchy. |
Bake Animations | Enable this when using IK or simulation in your animation package. Unity will convert to forward kinematics on import. This option is available only for Maya, 3dsMax and Cinema4D files. |
Animation Wrap mode | The default Wrap Mode for the animation in the mesh being imported |
Default | The animation plays as specified in the animation splitting options below. |
Once | The animation plays through to the end once and then stops. |
Loop | The animation plays through and then restarts when the end is reached. |
PingPong | The animation plays through and then plays in reverse from the end to the start, and so on. |
ClampForever | The animation plays through but the last frame is repeated indefinitely. This is not the same as Once mode because playback does not technically stop at the last frame (which is useful when blending animations). |
Split Animations | If you have multiple animations in a single file, you can split it into multiple clips. |
Name | The name of the split animation clip |
Start | The first frame of this clip in the model file |
End | The last frame of this clip in the model file |
WrapMode | What the split clip does when the end of the animation is reached (this is identical to the wrap mode option described above). |
Loop | Depending on how the animation was created, one extra frame of animation may be required for the split clip to loop properly. If your looping animation doesn't look correct, try enabling this option. |
Animation Compression | |
Anim. Compression | The type of compression that will be applied to this mesh's animation(s) |
Off | Disables animation compression. This means that Unity doesn't reduce keyframe count on import, which leads to the highest precision animations, but slower performance and bigger file and runtime memory size. It is generally not advisable to use this option - if you need higher precision animation, you should enable keyframe reduction and lower allowed Animation Compression Error values instead. |
Keyframe Reduction | Reduces keyframes on import. If selected, the Animation Compression Errors options are displayed. |
Keyframe Reduction and Compression | Reduces keyframes on import and compresses keyframes when storing animations in files. This affects only file size - the runtime memory size is the same as Keyframe Reduction. If selected, the Animation Compression Errors options are displayed. |
Animation Compression Errors | These options are available only when keyframe reduction is enabled. |
Rotation Error | Defines how much rotation curves should be reduced. The smaller value you use - the higher precision you get. |
Position Error | Defines how much position curves should be reduced. The smaller value you use - the higher precision you get. |
Scale Error | Defines how much scale curves should be reduced. The smaller value you use - the higher precision you get. |
Material Generation and Assignment
For each imported material Unity will apply the following rules:-
If material generation is disabled (i.e. Import Materials is unchecked), then it will assign the Default-Diffuse material. If it is enabled then it will do the following:
- Unity will pick a name for the Unity material based on the Material Naming setting
- Unity will try to find an existing material with that name. The scope of the Material search is defined by the Material Search setting.
- If Unity succeeds in finding an existing material then it will use it for the imported scene, otherwise it will generate a new material
Colliders
Unity uses two main types of colliders: Mesh Colliders and Primitive Colliders. Mesh colliders are components that use imported mesh data and can be used for environment collision. When you enable Generate Colliders in the Import Settings, a Mesh collider is automatically added when the mesh is added to the Scene. It will be considered solid as far as the physics system is concerned.
If you are moving the object around (a car for example), you can not use Mesh colliders. Instead, you will have to use Primitive colliders. In this case you should disable the Generate Colliders setting.
Animations
Animations are automatically imported from the scene. For more details about animation import options see the Animation Import chapter.
Normal mapping and characters
If you have a character with a normal map that was generated from a high-polygon version of the model, you should import the game-quality version with a Smoothing angle of 180 degrees. This will prevent odd-looking seams in lighting due to tangent splitting. If the seams are still present with these settings, enable Split tangents across UV seams.
If you are converting a greyscale image into a normal map, you don't need to worry about this.
Hints
- Merge your meshes together as much as possible. Make them share materials and textures. This has a huge performance benefit.
- If you need to set up your objects further in Unity (adding physics, scripts or other coolness), save yourself a world of pain and name your objects properly in your 3D application. Working with lots of pCube17 or Box42-like objects is not fun.
- Make your meshes be centered on the world origin in your 3D app. This will make them easier to place in Unity.
The Unity Editor shows too many triangles (compared to what my 3D app says)
This is correct. What you are looking at is the number of triangles actually being sent to OpenGLES for rendering. In addition to the case where the material requires them to be sent twice, other things like hard-normals and non-contiguous UVs increase vertex/triangle counts significantly compared to what a modeling app or Unity tells you. Triangles need to be contiguous in both 3D and UV space to form a strip, so when you have UV seams, degenerate triangles have to be made to form strips - this bumps up the count. Previously Unity would report triangle counts incorrectly. This was fixed first in the run-time, and recently in the Editor. Now both will report the correct number of triangles actually being sent to OpenGLES for rendering.