Substances Caching Problems

For the current project I am working on, I am using custom substances materials that our team has created. We have roughly 30 substances each with 2 procedural materials that generating about 8-12 512x512 maps per substance.

Initially, these were all set to build on level load but this turned out to be a fairly intensive process and often models were shown before the material had been fully generated. Instead we changed all the substances to “Bake and Keep Substance” in an attempt to cache the textures and to save on processing at runtime.

However, more often than not, we get poorly cached or ungenerated textures that cover our models and because it thinks the textures are already baked, they are not recomputed again and show up as anomalies (see images case-1.jpg and case-3.jpg). However, if I stop the project and goto the project and select the substance and refresh each material inside (just by clicking them), after restarting the scene, that specific substance is fine again, but other substances can/will have become erroneous.

Is there a proper way to caches these? Or is there an approach where it involves a loading screen to properly process all these textures before they are used?

Thanks for any insight into this problem. I’m not sure if it is a memory issue or not but 512x512 maps shouldn’t be that intensive.



I’m not sure if this is the best solution or of it is consistent yet but I’ve added this function to “preload” the substances:

public void BuildSubstances(){
        Object[] proceduralMaterialObjects = Resources.LoadAll("Substances", typeof(ProceduralMaterial));
    
        foreach (ProceduralMaterial material in proceduralMaterialObjects) {
            Debug.Log("Building "+material.name);
            material.RebuildTexturesImmediately();
            Debug.Log("Completed "+material.name);
        }
}

Which can be swapped to:

material.RebuildTextures()

or converted into a IEnumerator:

public IEnumerator BuildSubstances()

depending on implementation but then you would require a loading screen to hide the scene while these are being processed.