- Home /
How do you instantiate a Procedural Material?
I'm trying to set up a basic Procedural Material, and I am having no luck. The docs and a simple example for the class are here: http://docs.unity3d.com/ScriptReference/ProceduralMaterial.html but I can't find any tutorials or other examples online. This class isn't deprecated is it?
Here's the inspector for a single cube on which I've attached a Proc Mat Handler script:
The script (Proc Mathandler) is exactly as copied from the docs:
using UnityEngine;
using System.Collections;
public class ProcMathandler : MonoBehaviour {
public string floatRangeProperty = "Saturation";
public float cycleTime = 10;
public Renderer rend;
void Start() {
rend = GetComponent<Renderer>();
}
void Update () {
ProceduralMaterial substance = rend.sharedMaterial as ProceduralMaterial;
if (substance) {
Debug.Log("Found a substance");
// Make the property go up and down over time
var lerp = Mathf.PingPong (Time.time * 2 / cycleTime, 1);
substance.SetProceduralFloat (floatRangeProperty, lerp);
substance.RebuildTextures ();
}
Debug.Log("Did not find a substance");
}
}
Unfortunately, substance is always null. rend.SharedMaterial returns the proper Material, but when I cast it to a ProceduralMaterial, something goes wrong.
Anybody know what that is?
Thanks, Sam
Answer by tanoshimi · Feb 08, 2016 at 05:29 PM
Based on the screenshot you've shown, it's hard to tell whether the material attached to this gameobject is a procedural substance or not. If you expand the inspector for the material, do you see procedural options like this?:
How did you create the SBSAR file?
Answer by Wellmann · Feb 24, 2016 at 03:08 PM
rend.sharedMaterial will give you a reference to the main ProceduralMaterial waht you want to do is renderer.material. But be aware that renderer.material will clone the ProceduralMaterial.
To give more than one object the same Material have a look have a look here http://answers.unity3d.com/questions/289785/cloning-substance-procedural-material-at-runtime.html
Be aware you can't use Instantiate() on a ProceduralMaterial
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Best way to procedurally generate materials with text 0 Answers
Trouble with Procedural Mesh Normals (normals are inverted) 1 Answer
Trouble with Inaccurate Mesh Collider 0 Answers