substance designer to maya to unity workflow

Overview

My general workflow is to create my materials in Allegorithmic Substance Designer, build my assets in Autodesk Maya and then import the assets into Unity.

Unity has a number of ways of auto-assigning unity materials based upon assignments/naming in maya, general documentation can be found under the FBX importer documentation this post covers how I have adapted this to fit into my workflow with Substance designer and Maya.

The basics

Step 1: (only needs to be done once per unity project)

Setup an AssetPostprocessor script

Step 2:

Place your substance files in a convenient place on disk.

Step 3:

In maya, create a substance network for each material.

Step 4:

Import your substance files into unity.

Step 5:

Import your asset.

Setting up the asset pre-processor script

The unity tool kit has a number of hooks to allow us to extend the game editor and how it processes models. One of these classes is the AssetPostprocessor. The AssetPostprocessor class gives us access to assets as they are being imported into the editor.

In order for the script to be used it must be in a folder called Editor or a sub-folder of the Editor directory. Your project can have more then one Editor folder, however I prefer to keep my project organization fairly simple. My projects only contain one Editor folder and it is at the root level of the project. This way all my editor scripts are in one place and I only have one place in my project to search for editor scripts. In general, all editor scripts will be in that folder but if a group of the scripts is logically connected then I will put them in a subfolder.

The AssetPostprocessor supports a number of functions, but in this case we are only interested in one: material assignment. The OnAssignMaterialModel function will be called once per material assignment on each mesh. It will be provided with a unity material, named based upon the naming scheme described in the FBX importer documentation. If the function returns a valid material then that material will be assigned to the mesh. If it returns null then unity will apply a material based upon the standard import rules described previously.

The full code to automatically assign substance materials is as follows (This is a c sharp script).

In my case there is a little bit of special munging to the file names so that everything lines up. First, in maya, I suffix all materials with _mtl, so we strip that off. Second, in order to load assets, we need to add the file suffix onto the name, so we add .sbsar. Finally, we have to supply the LoadAssetAtPath command with a path relative to our project route, so we have to assemble that path.

Most examples will choose to create a material if an existing material can not be found and a logical choice would be to create something that stands out so that you can see the error. For the sake of simplicity I allow unity to create the material for me if I can’t find a valid substance material.

Place your substance files in a convenient place on disk

In my previous post on project structure I had laid out this project structure:

    • unity_workshop
      • unity_project
      • maya_project
      • sandbox

I’ve extended this project structure to include a sub directory for storing my substance files. I currently store my substance project files and the final published substance in this directory.

    • unity_workshop
      • unity_project
      • maya_project
      • sandbox
      • substances

Each material receives it’s own sub directory. The project file and the published material will be at this level. If the substance relies on any image files they will be stored inside of an images subdirectory. For example, the material DecaledPlastic looks like this:

    • DecaledPlastic
      • DecaledPlastic.sbs
      • DecaledPlastic.sbsar
      • images
        • Decal.svg
In maya, create a substance network for each material

To create substance based material for maya you have to add a substance node and then create a material that uses the substance. In order to easily differentiate between different node types in maya, I always use add suffixes to my nodes. Any substance node ends in _sbsar, any material ends in _mtl

Our asset without any materials on it looks like this:

Basic_un_textured_material

So first create the substance node:

ClickOnSubtanceNode

The result is a very simple graph:

Substance_created

Then, I rename it to the substance I am using. In this case: decaledplastic_sbar

Now, we need to point the substance node at our substance

ChooseSubstance

Once we have done that, we can create the shader network.

Create_shader_network
This will create a full shader network.

material_network

Rename the material node to match our naming scheme: decaledplastic_mtl

Assign the material to our geometry:

assigned_mtl
Export our geometry to fbx

Import your substance files into unity

In unity, go to your materials folder and then do “Import new asset”. Select your decaledplastic substance. You should end up with this material in your scene.

UnityImportedSubtance

Import your asset

Go to any folder in your project and do “Import new asset”. Select you exported geometry.

UnityImportedAsset

AssignedMaterial

And you are done.

LevelsOfThinking