Search Unity

Attempting to Editor-script changing the shader in ProceduralMaterials

Discussion in 'Editor & General Support' started by cory_munky, Apr 13, 2016.

  1. cory_munky

    cory_munky

    Joined:
    Dec 10, 2014
    Posts:
    66
    I would expect the code below to work. And, when I debug it, I can watch all of the values change correctly. But, afterwards the assets in the Editor show no change.

    Any clues as to what I'm missing?

    Code (CSharp):
    1.         SubstanceImporter importer = AssetImporter.GetAtPath("assets/bundled/materials/commandcenter1.sbsar") as SubstanceImporter;
    2.         Shader shader = Shader.Find("PbrNormOcc");
    3.         var mats = importer.GetMaterials();
    4.         foreach(var mat in mats)
    5.             mat.shader = shader;
    6.         importer.SaveAndReimport();