I’ve searched through all the discussion on it and it seems pretty inconclusive. Has anyone figured out how to load a .sbsar file from the asset folders instead of attaching it to a GameObject in the editor first? So far I’ve tried a large number of things, but have seen two functions I know little about - SubstanceArchive and SubstanceImporter.
Please note this code is extrapolated from my overall project, it’s not intended to be pasted and run immediately, I will work on making it that way, but until then, please note.
Here’s a nutshell of everything I’ve tried so far, there are three .sbsar files in a folder - “Assets/Resources/sbsar”:
private ProceduralPropertyDescription[] curProperties;
private UnityEngine.Object[] subLoad;
private GameObject subGO;
private ProceduralMaterial[] buildingpiecesmaterial;
subLoad = Resources.LoadAll("sbsar", typeof(ProceduralMaterial));
buildingpiecesmaterial[0] = (ProceduralMaterial) subLoad[0];
subGO = new GameObject("Substances");
MeshRenderer tempRender = subGO.AddComponent<MeshRenderer>();
tempRender.material = buildingpiecesmaterial[0] as ProceduralMaterial;
ProceduralMaterial tempMaterial = tempRender.material as ProceduralMaterial;
curProperties = tempMaterial.GetProceduralPropertyDescriptions();
int i = 0;
while(i < curProperties.Length) {
Debug.Log (curProperties[i].name.ToString () + " is of type: " + curProperties[i].type.ToString ());
i++;
}
The output of the code is always pixel size as a Vector2 and random seed as a float. I can never seem to get my own exposed variables to load. I feel like it’s just initializing an empty Procedural Material, except if it’s applied to a mesh it loads the first material listed in Unity’s Asset window under the substance, so it’s at least referencing the correct file.