Choosing a project structure for unity development

Overview
Getting started is always the hardest part. How will my project be structured? What settings do I need to worry about? How will my software interact? For example, what does one unit of measurement mean? Does this change in the various software packages?

What do can I figure out on the fly? And what do I need to set up from the start?

I had already decided to use unity and maya for this project because I know maya and because I want to learn unity. For the purpose of this experiment, I am going to try to use this structure

     

          • unity_workshop
            • unity_project
            • maya_project
            • sandbox
    Why choose this structure?

    This structure provides me both encapsulation and separation. Everything associated with this project is stored under the unity_workshop directory, but the maya work is stored outside of the unity project. I realize that I could have setup the project so that I was working directly in unity, including storing my maya scene files inside of my unity project however I prefer the separation for two reasons.

    1. It allows me to organize my maya scenes independently of how unity organizes its files
      Why is this an advantage?
    2. I intend to use fbx to transfer my assets and animation from maya to unity
      Why not use unity's built in maya importer?

    Your working structure is obviously something that you should figure out in advance. Usually, you know all the tools involved and you can make choices based upon known issues/advantages. In this case, I’m guessing that this will be my optimal structure.

    What is my unit of measurement?

    Scale impacts your workflow in many different ways.

    From the creative standpoint, you need to think about the user experience inside of the game. Are the players human sized in a human world? Or are they humans in a giants world? The answers to this question will dictate how fast things move, relative scale and game point of view.

    From a technical point of view, the unit of measurement and scale of the world can have a significant impact on the performance of your game; if you treat your units as a very small unit (such as centimeters) but are building a world where the characters are 20 meters tall you can literally run out of numbers to represent the finer details. Especially as your characters move away from the origin of the world. Furthermore, while units are arbitrary typical simulation engines often make assumptions about what 1 unit means. So, if the physics engine believes that 1 unit is equal to 1 meter but you treat 1 unit as 1 centimeter, then your object is not going to behave as if it has the correct mass.

    As it turns out unity does not have a user interface for specifying what one unit of measurement means? However it’s physics engine does treat 1 unit as 1 meter. Since meters are a reasonable unit of measurement for human sized buildings and props and my initial game experiments will take place in human sized worlds I will use 1 unit equal to 1 meter.

    So what does this mean for maya? Maya does allow you to change the scale of your working units. You can find this under:

    ”settings/preferences->preferences->settings->working

    However, universal recommendation is to always leave this value at centimeters. If you ask why most people will simply say bad things will happen if you don’t. For me, the biggest problem has been people working at inconsistent units of measurement.

    After you decide on a standard unit of measurement you should always perform a conversion test between your packages to make sure that what you expect is happening does happen.

    So, I start by going to maya and making a 1 unit sized cube.

    1 cm cube

    In theory, if I save this file as a maya file and import it into unity using the “Assets->Import New Asset” menu I should get a cube that is 1/100th the size of a cube created in unity using “GameObject->Create->Other->Cube”

    Unity 1 primative cube

    However, when I bring my “single unit” cube into unity and place it next to the primitive object. I see that it is the same size as my “1 unit (meter)” cube that I created in unity.

    Comparison between maya unit cube and unity unit cube

    What this means is that unity does not do any unit conversion when you import a maya file. Instead, it treats the units as if they are unity’s 1 meter units. This can be fine, as long as you build all your assets this way. So, if you need to build a two meter long prop, in maya you would build it two centimeters long.

    So, let’s see what happens if I export my unit cube to an fbx file and then import that file.

    default options fbx export

    If I import this cube, it is 1/100th the size of my unity cube. This is the result that I wanted because, my cube in maya is 1 centimeter.

    Comparison 1 centimeter cube to 1 meter cube

    There is one obvious question when looking at the comparison: Why does unity’s unit cube have a scale of 1,1,1 and my imported cube have a scale of 1,1,1 and yet they are different sizes. Did unity’s fbx importer scale my mesh? Well sort of. When you imported your asset unity applied a scale factor. This can be found by selecting the asset in project window and looking at it in the inspector.

    asset inspector

    You can change this value on any imported asset at any time.

    So, what if you have a number of assets modeled with the wrong units. How can you fix this? You would naturally want to go to the fbx file exporter and change the unit conversion to meters.

    fbx exporter unit scale

    But as you can see, that is going to apply a scale factor of .01. Also, when you import the file into unity the scale factor will also be set, pushing your asset further out of scale with the world. There is a work around however.

    You can create a script that is executed after each asset is imported into unity. That script is responsible for setting the scale factor of the asset.

    You place the script into a folder called editor. The script itself is very simple C# script:

    FBX scale post process snippet

    I’m sure that I will have to revisit the question of scale once I start transferring skinned assets and animation.

    LevelsOfThinking