Clear()
Clear material property values.
Read time 1 minuteLast updated 7 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
public void Clear()
Remarks
Graphics.RenderMesh copies the passed property block, so the most efficient way of using it is to create one block and reuse it for all RenderMesh calls. Use MaterialPropertyBlock.Clear to clear block's values, and MaterialPropertyBlock.SetFloat, MaterialPropertyBlock.SetVector, MaterialPropertyBlock.SetColor, MaterialPropertyBlock.SetMatrix to add values.
Examples
using UnityEngine;public class Example : MonoBehaviour{ // Assign a mesh in the Inspector, for example the built-in Cube mesh public Mesh mesh; Material material; MaterialPropertyBlock propertyBlock; void Start() { material = new Material(Shader.Find("Universal Render Pipeline/Lit")); // Create one property block and reuse it for all RenderMesh calls propertyBlock = new MaterialPropertyBlock(); } void Update() { RenderParams renderParams = new RenderParams(material); renderParams.matProps = propertyBlock; // Clear any property and add a red color propertyBlock.Clear(); propertyBlock.SetColor("_BaseColor", Color.red); Graphics.RenderMesh(renderParams, mesh, 0, Matrix4x4.Translate(new Vector3(5, 0, 0))); // Clear any property and add a green color propertyBlock.Clear(); propertyBlock.SetColor("_BaseColor", Color.green); Graphics.RenderMesh(renderParams, mesh, 0, Matrix4x4.Translate(new Vector3(-5, 0, 0))); }}