Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

MaterialPropertyBlock

Namespace: UnityEngine

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.

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 Clear to clear block's values, and AddFloat, AddVector, AddColor, AddMatrix to add values.

See Also: Graphics.DrawMesh, Material.

Functions

AddColorAdd a color material property.
AddFloatAdd a float material property.
AddMatrixAdd a matrix material property.
AddTextureAdd a texture material property.
AddVectorAdd a vector material property.
ClearClear material property values.
GetFloatGet a float from the property block.
GetMatrixGet a matrix from the property block.
GetTextureGet a texture from the property block.
GetVectorGet a vector from the property block.