Copying Substances

Hi,
I’ve been searching for a while on this subject, but hadn’t much luck

How do I make during runtime a copy of a ProceduralMaterial and edit it without influencing the original ?.
For some reason the Material constructor used to “clone” a source material doesn’t work
Material Documentation
And method suggested here for standard materials, doesn’t apply to Substances

My goal is having just this one material, and occasionally randomize it’s values on certain objects, and i’d like to do it just at runtime, without touching my assets, or leaking materials.

Thank you !

1 Answer

1

hm ok, i managed to do that, writing this function

function new_proc_mat()
{
	var mat_dummy = Instantiate(a_dummy_gameobj,Vector3.zero,Quaternion.identity);
	mat_dummy.renderer.material = original_proc_material;
	var tempmat = mat_dummy.renderer.material;
	var outputmat:ProceduralMaterial = tempmat;
	outputmat.SetProceduralFloat("$randomseed",Random.Range(0,10000));
	outputmat.RebuildTexturesImmediately();
	Destroy(mat_dummy);
	return outputmat;
}

But isn’t it a bit rusty, for just making an indipendent copy of a procedural material ?
Any suggestions on how to make it cleaner, and maybe without instancing dummy objects ?
Don’t get me wrong, i happily achieved my goal, at this point i’m just curious, and want to turn this dead post into something costructive :slight_smile:

have a good day!