- Home /
Set up Maya/FBX file so that it is automatically assigned an existing material on import?
Is there a way to set things up so that a newly imported FBX is automatically assigned an existing material? Based on the Unity docs it seems that this this should be possible but so far I am unsuccessful. From the docs...
"Materials are found based on the following rules:
Unity gets the name of the main diffuse material bound to the objects in the scene.
Unity looks for a material with this name in a Folder called Materials next to the scene.
Unity goes up the project folders, looking for the Material in each Materials folder along the way."
So basically what I tried is as follows:
1) Create a material in Unity called "MyMaterial"
2) In Maya create a mesh and assign it a material called "MyMaterial"
3) Export an fbx called "MyObject.fbx"
4) Launch Unity
At this point I would expect Unity would search the directory hierarchy upwards from "MyObject.fbx" and find "MyMaterial". However, it only seems to find the material if it is in a folder called Material which is sibling to the "MyObject.fbx". If that does not exist then it creates a new material called "MyMaterial" in a sibling folder.
Thanks!
I remembered being mentioned, you shouldn't ever change something directly in the folder... Just change it manually, takes about an extra 5 seconds, and if you use UV maps, and get $$anonymous$$udbox or something of the like, you can do it all there and then import to Unity...
Ultimately the problem I want to solve is one where I have a material shared by many objects. For example say I have a level with a bunch of buildings which share "BrickWall$$anonymous$$aterial". It would be nice within $$anonymous$$aya to assign a new building "BrickWall$$anonymous$$aterial", export to FBX and then have it automatically be assigned the correct material within Unity. Rather than have to manually hook it up and remove auto generated materials. Especially if this has to be done any time said building is adjusted and re-exported.
Answer by loopyllama · Mar 24, 2011 at 04:43 AM
This doesn't solve the problem of "I want to assign an arbitrary material" but this does solve the "I have a material shared by many objects...auto assign that material on import".
I have found that it works when the material import setting is "per texture" and that I export the fbx to the same folder as the texture. For example a structure of /models/background/ where the material lives in /models/background/Materials...if you place the texture for that material in /models/background and you export your fbx files to the /models/background folder AND the source 3d file has a material that uses that texture AND the import setting is the default "per texture" under material generation, you will find it will finally be auto-assigned on import into unity. In this case I believe the name of the materials are unimportant.
I hope there is another better way but I know this way works and I am tired of fighting unity on it, so I just use the method described above.
Answer by Paulius-Liekis · May 09, 2011 at 08:56 AM
Unity looks for a material with this name in a Folder called Materials next to the scene.
Unity goes up the project folders, looking for the Material in each Materials folder along the way.
It's a "bug" in Unity docs. Unity doesn't search for materials with the same name. It only searches for material which same texture. Which means if you assign MyTexture.png to your material in both Unity and Maya, then Unity will try to link material.
But speaking in general I like using AssetPostprocessor.OnAssignModelMaterial and taking full control of how materials are assigned to models.