Search Unity

AssetPostProcessor failing to run modelImporter.SearchAndRemapMaterials

Discussion in 'Scripting' started by petey, May 10, 2019.

  1. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Hi all!
    I've really been getting into the AssetPostProcessor lately. It's great for speeding up pipelines, but I can't seem to get modelImporter.SearchAndRemapMaterials working :(
    Does something look out of whack with this script? It just seems I still have to press the button manually to make it actually work.
    Any ides what I might be doing wrong there?

    Code (CSharp):
    1.     void OnPostprocessModel(GameObject g)
    2.     {
    3.         ModelImporter modelImporter = assetImporter as ModelImporter;
    4.         if (modelImporter.materialSearch == ModelImporterMaterialSearch.Everywhere)
    5.         {
    6.             Debug.Log("Full Projet search for existing materials for ->> " + g.name);
    7.             modelImporter.SearchAndRemapMaterials(ModelImporterMaterialName.BasedOnTextureName, ModelImporterMaterialSearch.Everywhere);
    8.         }
    9.     }

    Thanks!
    Pete