How can I edit the properties of Procedural Materials at runtime?

How can I edit the properties of Procedural Materials at runtime? For example, I want to edit the “Flow” Property of the “Electric_Liquid”, so I wrote a script that looks sort of like this and attached it to the offending object:

var flowval:float=0;
function Update () {
	var substance : ProceduralMaterial = renderer.sharedMaterial as ProceduralMaterial;
	if (substance) {
		flowval=flowval+Time.deltaTime;
		substance.SetProceduralFloat("Flow",flowval);
    	substance.RebuildTextures();
	}
}

My question is, because this doesn’t work, how can I make this work?

I am not that experienced with procedural materials, but I know that RebuildTextures is asyncronous. So you need to wait until it is done.
Either use RebuildTextures and wait until it is done (by checking it in each frame) or use RebuildTexturesImmediately, such that everything is stopped until the texture is calculated.

WARNING! UNTESTED CODE!

var flowval:float=0;
function Update () {
	flowval=flowval+Time.deltaTime;
	var substance : ProceduralMaterial = renderer.sharedMaterial as ProceduralMaterial;
	if (substance  !substance.isProcessing) {
		substance.SetProceduralFloat("Flow",flowval);
    		substance.RebuildTextures();
	}
}

or

var flowval:float=0;
function Update () {
	flowval=flowval+Time.deltaTime;
	var substance : ProceduralMaterial = renderer.sharedMaterial as ProceduralMaterial;
	if (substance) {
		substance.SetProceduralFloat("Flow",flowval);
    		substance.RebuildTexturesImmediately();
	}
}

Actually the code in the first post should work, you don’t have to wait for the RebuilTextures to end to call it another time, it will simply rebuild as soon as the previous call ended. Check in the substance inspector during runtime if the value changes at all. You may be hitting the maximum vale for the tweak too fast.