- Home /
Is it possible to retrieve materials from already imported mesh (with material import settings set to false)?
Hi!
I have a game with thousands of characters. Each consist of multiple materials. That results in a huge amount of material files in the project.
I'd like to solve this by having mesh settings set to NOT import materials and create them in runtime instead. The only thing i want to keep is the name of the material for each submesh.
Apparently that information is lost when import materials is ticked false in the settings for the mesh. Do i need to make a custom fbx importer or is there a more clever way of just retrieving the materials?
I don't know of a code way to solve this, but there's perhaps another way.
If you have access to the resource files (maya, blender, whatever), try to create a na$$anonymous$$g convention for materials (e.g. $$anonymous$$at01, $$anonymous$$at02).
If all models have unique names, you can create materials made up by a combination of both ($$anonymous$$odel01_$$anonymous$$at01, $$anonymous$$odel02_$$anonymous$$at01, etc.)
Otherwise you could create a text file storing the materials used for each mesh.
This would allow you to reuse materials for multiple meshes and easily switch them out by changing the file.
Take a look at the PostProcessor, there are callbacks for OnPreprocess$$anonymous$$odel and OnAssign$$anonymous$$aterial$$anonymous$$odel that might help you here:
https://docs.unity3d.com/ScriptReference/AssetPostprocessor.html
You might need to reimport the models in question to invoke the processor.
Your answer
Follow this Question
Related Questions
Imported mesh loses material information when assigning to triangles array 2 Answers
materials and textures import from max. 1 Answer
Blender FBX - Material Generation on Import Weirdness 1 Answer
share materials from imported Sketchup fbx 0 Answers
Get Max material information during import into Unity 0 Answers