Legacy Documentation: Version 4.6.2
Language: English
  • C#
  • JS
  • Boo

Script language

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

MaterialPropertyBlock

Namespace: UnityEngine

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

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 SetFloat, SetVector, SetColor, SetMatrix, SetTexture to add or replace values.

See Also: Graphics.DrawMesh, Material.

Functions

AddColor Add a color material property.
AddFloat Add a float material property.
AddMatrix Add a matrix material property.
AddTexture Add a texture material property.
AddVector Add a vector material property.
Clear Clear material property values.
GetFloat Get a float from the property block.
GetMatrix Get a matrix from the property block.
GetTexture Get a texture from the property block.
GetVector Get a vector from the property block.
SetColor Set a color property.
SetFloat Set a float material property.
SetMatrix Set a matrix material property.
SetTexture Set a texture material property.
SetVector Set a vector material property.