“What?!” you cry, “I thought we were about to get into Unity…finally!” Agreed, it's time to walk around the space we've made. However, as is the case with much of 3D, effective preparation of assets in earlier stages yield superior results later. Cleaning up the file in Maya will ensure a smoother transition into Unity, and exporting manually from Maya will ensure only the needed assets get transferred.
Step 1: Open the scene in Maya. In this case, it will be the EntryWay.mb
file that we have been building in earlier tutorials.
Step 2: Delete All History. Choose Edit>Delete All by Type>History.
Why?
Hopefully you've been cleaning your history as you were working in Maya, but here's the chance to make sure there are no lingering unwanted data nodes floating around your file.
Step 3: Remove unused Materials. Open the Hypershade (Window>Rendering
Editors>Hypershade). Within the Hypershade choose Edit>Delete Unused Nodes.
Why?
If it's not used, why include it in the data being passed around?
Step 4: Check for orphaned nodes. Open the Outliner (Window>Outliner)
and make sure that all the elements listed there are accounted for in the scene. Occasionally, even after cleaning history, there can be some leftover remnants of modeling process in the past (groups without anything in them, or other null objects). If any of these are present, delete them.
Step 5: Double-check all the naming. In the Outliner and the Hypershade
make sure there are no pCube25 objects or lambert26 materials. Every object should have a descriptive name that makes sense not only to you, but would make sense to someone else inheriting the file.
Why?
Taking time in the middle of the creation process to name objects and materials is not a favorite of beginning artists or students. The students think they can select the object and know what it is, so who cares what the thing is actually named? The problem is twofold. First, when working in Unity and working with scripts, sometimes objects will be called by name, not by the Unity user selecting them. If there are 50 spheres in the scene, it really slows the process trying to track down exactly which sphere is what. Second, game production is very often a team activity. Even a project that a solo developer began can often end up being a team project before it sees release. Team members that inherit a poorly named file with poorly named assets within do not remain happy for long. Name your stuff.
Warnings and Pitfalls
Remember that there are some default materials here that can't be deleted (lambert1 and particlecloud1). Don't worry about those, they can be left as is. It's part of the beauty of manually exporting the Maya file that none of these default nodes will be included.
Export Options
Unity has attempted to make the Export/Import process very painless by doing a lot of the conversion process behind the scenes. Technically, this .mb file could just be dropped into the Assets folder of the Incursion–Unity file. Then in the background, Unity opens a version of Maya (the Render application actually) and converts the .mb into a .fbx, which it can then read. Unity actually does this with any of the file formats it supports (i.e., opens C4D and exports the C4D file into an .fbx). On the surface this seems like a really amazing and painless process as Unity “automagically” converts bunches of things into the formats it uses.
However, I have found through many projects that I prefer to manually export files from their respective applications. Here are my reasons:
• When Unity does the conversion (via the 3D software), there is no way of
knowing what version of FBX the 3D software is attempting to use and if that particular version is compatible with the version of Unity being used. For instance, there were some significant differences between FBX2010 and FBX2011, and FBX2011 stuff was not coming into Unity at all until Unity had a chance to catch up with the new file format.
• While Unity is doing the converting, you are powerless to intervene in
the process. If it crashes, is it crashing on export from the 3D application or crashing on import into Unity? Very tough to troubleshoot without knowing which is the problem.
• When Unity does the conversion, it is up to the user to include all the
relevant texture files that are used in the scene. If the user misses a file, Unity forgets that the material is ever tied to it, which means the materials all have to be relinked manually. It's quick to do this but can add up quickly.
• By manually exporting you are creating another backup of your model and
work in another file format. As a professor, I have seen at least one student each semester with a .mb file that suddenly shows up at 0 kb—it's gone. While using Incremental Saves in Maya can help prevent some tears, it is certainly nice to have the asset in another format in case something goes bad with your Maya install, or some other catastrophe happens mid-production cycle.
• In a team situation, manually exporting from Maya means that other
members of the team do not have to have Maya installed on their machines to access the files that are output. This means that a team could have artists using a wide variety of 3D applications, and they could all be assembled on a machine without any licenses of the 3D applications (perhaps used by a scripter or programmer).
• By manually exporting the file from Maya, all the necessary textures can
be embedded into the .fbx exported. This means one file is moved into the Assets folder for each Maya scene built. When Unity unpacks the .fbx it will create a sister folder where it includes all the relevant textures. This means that automatically, all the textures involved in a particular Maya scene are organized. It makes it easier to find assets when in the midst of heated Unity development.
So, if you buy my reasoning, here are the simple steps to manually control the export/import process in Unity.
Step 6: In Maya, choose File>Export All.
Step 7: In the Export All dialog box, change the Files of type: drop-down
menu to FBX export.
Step 8: In the Options… section of the Export All dialog box expand the
File Type Specific Options, then the Include section, and finally the Embed Media. Check the Embed Media option.
Why?
Embed Media means that all the textures used in the scene will be included in the .fbx file that is exported. It essentially packages all the used textures and keeps them with the geometry file.
Step 9: Still in the Export All dialog box, expand the Advanced Options
and the FBX File Format options within. In the Version drop-down menu choose FBX 2010.
Why?
FBX2011 is a new format that has had some problems with early versions of Unity 3. By using FBX 2010, all the important characteristics are carried through to Unity, but with a much more reliable flow. Unity has a good habit of catching up with hotfixes, and hopefully the FBX2011 wrinkles will all be ironed out. Knowing and controlling the export format, however, is still an important part of the troubleshooting process.
Step 10: Enter EntryWay into the File name: input field and navigate to the
Assets folder of Incursion–Unity. Press Export All (Figure 5.4).
Tips and Tricks
Next time a file is exported from Maya, these settings will be remembered. So it takes just a moment to set up a reliable workflow, but things go much smoother when it ends up in Unity. Do remember that these settings have been changed. Maya works hard to remember what settings were changed last time, and if you're dealing in other situations, you may not want these same settings.
The Import Process
Interestingly enough, by saving the EntryWay.fbx file into the Assets folder, a big chunk of the importing has been done. When Unity is swapped to or launched (and make sure it's pointed at the Incursion–Unity project file), Unity will look at this new .fbx file and start chewing on it.
Warnings and Pitfalls
These steps are very specific to Maya 2011. If you are using any earlier version of Maya be aware that the step details may be a bit different.
On a PC, disconcertingly the Unity interface will not be visible except for an Importing Assets: progress bar (although Windows 7 will show some nice detail of progress in the Taskbar). On a Mac, usually there is a bit more of the Unity interface visible. But either way, watch for this progress bar to know that Unity is working on understanding the new assets it has been presented with (Figure 5.5). Once Unity has indeed chewed on all the assets, the project file should look something like Figure 5.6.
There are several things worth noting in Figure 5.6. Let's start from the bottom up. The Standard Assets folder is actually the result of setting up the project and importing the Character Controller package. Any of the default packages that ship with Unity will be placed within this Standard Assets folder. It's a handy way to separate which scripts are yours and which came from Unity. It's wise to not place any non-Unity provided assets within this folder to keep track of what assets came from where.
Figure 5.4 The Export All dialog box with the two important settings to change before exporting.
Figure 5.6 Results of the export/import process. Figure 5.5 The Importing Assets progress bar may be the only indication that
The Materials folder is new since the EntryWay.fbx was imported. When Unity imported the .fbx and understood what it was, it created this folder and in it are all the materials that Unity has applied to the polygon meshes you built in Maya. We will be adjusting the attributes of these materials as time goes on. Generally, there is little need to mess with this folder or its organization. The EntryWay.fbm folder is the result (and benefit) of manually exporting the .fbx file from Maya. In this folder are all the texture files created for use in Maya. These specifically are the texture files that are used on the geometry contained in EntryWay.fbx.
EntryWay with its unique icon is the Prefab of the imported Maya .fbx. This is the
model created in Maya with the materials attached to the meshes. To understand what this is, we need to talk nomenclature for a minute.
Unity Nomenclature
GameObject
GameObjects are essentially things in your scene—anything that is in the
scene is a GameObject. GameObjects can be thought of as containers; they can contain all sorts of components including cameras, lights, geometry, audio sources, audio listeners, and so on. GameObjects can hold lots of components at once. For instance, look at the Hierarchy panel of the scene and there is a Main Camera object there. This is a GameObject with a Camera component on it. If the Main Camera is selected in the Hierarchy panel, the Inspector will show all the components that are actually attached to this GameObject (including an Audio Listener).
Sometimes, certain GameObjects include other important items like geometry. Looking at the Project panel, the prefab EntryWay is a type of GameObject that includes meshes with attached materials.
Prefabs
Prefabs are GameObjects that can be reused. Sometimes these prefabs
contain meshes, as EntryWay does, but they can also contain other types of components (audio, texture, text, particles, etc.). When prefabs are dragged into the Hierarchy panel (or into the Scene view, which also then populates the Hierarchy panel), an instance or copy is made in the scene. Multiple instances can be placed in the scene, and if the original prefab is ever altered the changes inherit down to all the instances placed within the scene.
Scenes
Unity thinks of Scenes in the same way that Maya does. A Unity scene file will contain lots of different assembled assets. Any particular game may contain several scenes that the player passes through over the course of the game. A scene can contain a single prefab, or many. Often multiple scenes can make for
a quicker startup to a game (since the starting scene does not contain the entire game), but means that there are loads as the player moves through the game. Currently in our tutorial, we do not have a Unity scene saved yet but we soon will. Now that we know a bit about what is in the Unity project, we can start assembling and tweaking a Unity scene.