Version: 2017.2

MaterialPropertyBlock

class in UnityEngine

Switch to Manual

Description

A block of material values to apply.

MaterialPropertyBlock is used by Graphics.DrawMesh and Renderer.SetPropertyBlock. Use it in situations where you want to draw multiple objects with the same material, but slightly different properties. For example, if you want to slightly change the color of each mesh drawn. Changing the render state is not supported.

Unity's terrain engine uses MaterialPropertyBlock to draw trees; all of them use the same material, but each tree has different color, scale & wind factor.

The block passed to Graphics.DrawMesh or Renderer.SetPropertyBlock is copied, so the most efficient way of using it is to create one block and reuse it for all DrawMesh calls. Use SetFloat, SetVector, SetColor, SetMatrix, SetTexture, SetBuffer to add or replace values.

See Also: Graphics.DrawMesh, Material.

Variables

isEmptyIs the material property block empty? (Read Only)

Public Functions

ClearClear material property values.
GetFloatGet a float from the property block.
GetFloatArrayGet a float array from the property block.
GetMatrixGet a matrix from the property block.
GetMatrixArrayGet a matrix array from the property block.
GetTextureGet a texture from the property block.
GetVectorGet a vector from the property block.
GetVectorArrayGet a vector array from the property block.
SetBufferSet a ComputeBuffer property.
SetColorSet a color property.
SetFloatSet a float property.
SetFloatArraySet a float array property.
SetMatrixSet a matrix property.
SetMatrixArraySet a matrix array property.
SetTextureSet a texture property.
SetVectorSet a vector property.
SetVectorArraySet a vector array property.