Best practice for cleaning up leaked procedural materials?
As is reasonably well-documented, when you modify renderer.material on a gameObject, it makes a new copy of the material, and that copy is not automatically destroyed when the gameObject is. This can cause memory leaks.
You can clean up these leaks by calling Resources.UnloadUnusedAssets() periodically, but that feels sloppy and almost definitely has unnecessary overhead. Theoretically, Resources.UnloadAsset() looks like a manual alternative, but it isn't working for me.
My materials are ProceduralMaterials (Substance Designer) and when I call UnloadAsset on one, it throws this exception:
UnloadAsset can only be used on assets: UnityEngine.Resources.UnloadAsset(Object)
I've seen suggestions to use DestroyImmediate, that doesn't seem to work either.
Is there a way to manually unload procedural materials? Should I just get over it and write a script to call UnloadUnusedAssets every couple minutes?