Let's say I have an asset A that contains materials X,Y,Z.
I have another asset B that also contains materials X,Y,Z.
I would like to import A and then import B and create only
materials X,Y,Z in unity3D. Instead, I am getting materials
A-X
A-Y
A-Z
B-X
B-Y
B-Z
Now imagine I want to import 500 assets that all use X,Y,Z.
I'd really rather not have 1500 materials when I only need 3.
Thanks for any tips or pointers!
I have a postprocessor that does just that: http://buchhofer.com/?p=228 adjust your paths to suit, and also your default shader type.
//file: MaterialsPostProcessor.cs
//goal: Share a library of materials across different assets
//based on the name of material supplied in the FBX file
//Dave Buchhofer - 02.10.2010
using UnityEngine;
using UnityEditor;
using System.Collections;
public class MaterialsPostProcessor : AssetPostprocessor
{
Material OnAssignMaterialModel (Material material, Renderer renderer)
{
//The path where you keep your "Standard" library of materials
string StandardMatPath = "Assets/DMGStandardMaterials/" + material.name + ".mat";
//the path where you want to keep your "temp" materials, that weren't found above
//So you have a logical place to look for materials that need editing and tweaking for realtime work.
string TemporaryMatPath = "Assets/Mesh/Materials/" + material.name + ".mat";
//Check for it in the standard
if (AssetDatabase.LoadAssetAtPath(StandardMatPath, typeof(Material)))
{
Debug.Log("FOUND: " + StandardMatPath);
return (Material)AssetDatabase.LoadAssetAtPath(StandardMatPath, typeof(Material));
}
//Else check to see if we've already built one in the temp path
if (AssetDatabase.LoadAssetAtPath(TemporaryMatPath, typeof(Material)))
{
Debug.Log("FOUND temp: " + TemporaryMatPath);
return (Material)AssetDatabase.LoadAssetAtPath(TemporaryMatPath, typeof(Material));
}
//Or create it?
material.shader = Shader.Find("Diffuse");
AssetDatabase.CreateAsset(material, TemporaryMatPath);
Debug.Log("CREATED temp: " + TemporaryMatPath);
return material;
}
}
You have to create a script for the assetPostprocessor to say that I want unity to assign these materials. Here is an example tool that creates colliders only for the objects containing the word collider in them.
The logic is the same, consider using user properties in your objects (Max,Maya) for more detailed control concerning materials.
Have a look at this answer too. here
I am still struggling to create a proper pipeline, but if you are more adept in coding it seems fairly easy to do whatever you want just by naming objects in your 3d app.