
Configuring assets
As we mentioned earlier, artists are used to creating art assets outside Unity, and that can cause differences between how the asset is seen from that tool and how Unity will import it. As an example, 3D Studio can work in centimetres, inches, and so on, while Unity works in meters. We have just downloaded and used lots of assets, but we have skipped the configuration step to solve those discrepancies, so let's take a look at this now.
In this section, we will cover the following concepts related to importing assets:
- Configuring meshes
- Configuring textures
Let's start discussing how to configure 3D meshes.
Configuring meshes
In order to change the model's import settings, you need to locate the model file you have downloaded. There are several file extensions that contain 3D models, with the most common one being the .fbx file, but you can encounter others such as .obj,.3ds, .blender, .mb, and so on. You can identify whether the file is a 3D mesh via its extension:

Figure 5.24 – Selected asset path extension
Also, you can click the Asset and check in the Inspector for the tabs you can see in the following screenshot:

Figure 5.25 – Mesh materials settings
Now that you have located the 3D mesh files, you can configure them properly. Right now, the only thing we should take into account is the proper scale of the model. Artists are used to working with different software with different setups; maybe one artist created the model using meters as its metric unit, while other artists used inches, feet, and so on. When importing assets that have been created in different units, they will probably be unproportioned, which means we will get results such as humans being bigger than buildings and so on.
The best solution is to just ask the artist to fix that. If all the assets were authored in your company, or if you used an external asset, you can ask the artist to fix it to the way your company works, but right now, you are probably a single developer learning Unity by yourself. Luckily, Unity has a setting that allows you to rescale the original asset before using it in Unity. In order to change the scale factor of an object, you must do the following:
- Locate the 3D mesh in your Project Window.
- Drag it to the scene. You will see that an object will appear in your scene.
- Create a capsule using the GameObject | 3D Object | Capsule option.
- Put the capsule next to the model you dragged into the Editor. See whether the scale makes sense. The idea is that the capsule is representing a human being (2 meters tall) so that you have a reference for the scale:
Figure 5.26 – Unproportioned asset
- If the model is bigger or smaller than expected, select the mesh again in the Project Window (not the GameObject instance you dragged to the Editor) and you will see some import settings in the Inspector.
- Look for the Scale Factor property and modify it, increasing it if your model is smaller than expected or reducing it in the opposite case:
Figure 5.27 – Model mesh options
- Click the Apply button at the bottom of the Inspector.
- Repeat steps 6 and 7 until you get the desired result.
There are plenty of other options to configure, but let's stop here for now. Now, let's discuss how to properly configure the textures of our models.
Configuring textures
Again, there are several settings to configure here, but let's focus on the texture size for now. The idea is to use the size that best fits the usage of that texture, and that depends on lots of factors. The first factor to take into account is the distance from which the object will be seen. If you are creating a first person game, you will probably see lots of objects near enough to justify a big texture, but maybe you have lots of distant objects, such as billboards at the top of buildings, that you will never be near enough to see the details of, so you can use smaller textures for that. Another thing to take into account is the importance of the object. If you are creating a racing game, you will probably have lots of 3D models that will be on-screen for a few seconds and the player will never focus on them; they will be paying attention to the road and other cars. In this case, an object such as a trash can on the street can have a little texture and a low-polygon model and the user will never notice that (unless they stop to appreciate the scenery, but that's acceptable). Finally, you can have a game with a top-down view that will never zoom in on the scene, so the same object that has a big texture in first person games would have a less detailed texture here. In the next figure, you can see that the smaller ship could use a smaller texture:

Figure 5.28 – The same model being seen at different distances
The ideal size of the texture is relative. The usual way to find it is by changing its size until you find the smallest possible size with a decent quality when the object is seen from the nearest position possible in the game. This is a trial and error method. In order to do that, you can do the following:
- Locate the 3D model and put it into the scene.
- Put the Scene view camera in a position that shows the object at its biggest possible in-game size. As an example, in an FPS game, it would be almost right next to the object, while in a top-down game, it would be a few meters above the object. Again, that depends on your game.
- Find and select the texture that the object is using in the folders that were imported with the package or from the material you created previously. They usually have the .png, .jpg, or .tif extensions.
- In the Inspector, look at the Max Size property and reduce it, trying the next smallest value. For example, if the texture is at 2,048, try 1,024.
- Click Apply and check the Scene view to see whether the quality has decreased dramatically or if the change isn't noticeable. You will be surprised.
- Repeat steps 4 to 5 until you get a bad-quality result. In that case, just increase the previous resolution to get an acceptable quality. Of course, if you are targeting PC games, you can expect higher resolutions than mobile games.
Now that you have imported, integrated, and configured your objects, let's just create our Player's Base with those assets.
Assembling the scene
Let's start replacing our prototype base using the environment pack we have downloaded. To do that, you must do the following:
- In the Environment pack, locate the folder that contains all the models for the different pieces of the scene and try to find a corner. You can use the search bar in the Project Window to search for the corner keyword:
Figure 5.29 – Mesh picker
- In my specific case, I have the outer and inner side of the corner as separate models, so I need to put them together.
- Position it in the same position as any corner of your prototype base:
Figure 5.30 – Positioning the mesh on a placeholder for replacement
- Find the proper model that will connect with that corner to create walls. Again, you can try searching for the wall keyword in the Project Window.
- Instance it and position it so that it's connected to the corner. Don't worry if it doesn't fit perfectly; you will go over the scene when necessary later.
Important Note
You can select an object and press the V key to select a vertex of the selected object to drag it to a vertex of another object. This is called vertex snapping. It allows you to connect two pieces of a scene exactly as you intend:
Figure 5.31 – Connecting two modules
- Repeat the walls until you reach the other end of the Player Base and position another corner. You might get a wall that's a little bit larger or smaller than the original prototype, but that's fine:
Figure 5.32 – Chain of connected modules
Important Note
Remember that you can move an object while pressing the Ctrl key (Control on Mac) to snap the object´s position so that the clones of the wall can be easily located right next to the others.
- Complete the rest of the walls and destroy the prototype. Remember that this process is slow and you will need to be patient.
- Add floors by looking for floor tiles and repeating them all over the surface:
Figure 5.33 – Floor modules with a hole for the pit
- Add whatever details you want to add with other modular pieces in the package.
- Put all those pieces in a container object called Base. Remember to create an empty object and drag the base pieces into it:

Figure 5.34 – Mesh Sub-Assets
After a lot of practice doing this, you will slowly gain experience with the common pitfalls and good practices of modular scene design. All the packages have different modular designs in mind, so you will need to adapt to them.