A block of material values to apply.
MaterialPropertyBlock is used by Graphics.RenderMesh 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.RenderMesh 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.
Note that this is not compatible with SRP Batcher. Using this in the Universal Render Pipeline (URP), High Definition Render Pipeline (HDRP) or a custom render pipeline based on the Scriptable Render Pipeline (SRP) will likely result in a drop in performance.
See Also: Graphics.RenderMesh, Material.
isEmpty | Is the material property block empty? (Read Only) |
Clear | Clear material property values. |
CopyProbeOcclusionArrayFrom | This function copies the entire source array into a Vector4 property array named unity_ProbesOcclusion for use with instanced Shadowmask rendering. |
CopySHCoefficientArraysFrom | This function converts and copies the entire source array into 7 Vector4 property arrays named unity_SHAr, unity_SHAg, unity_SHAb, unity_SHBr, unity_SHBg, unity_SHBb and unity_SHC for use with instanced light probe rendering. |
GetColor | Get a color from the property block. |
GetFloat | Get a float from the property block. |
GetFloatArray | Get a float array from the property block. |
GetInt | This method is deprecated. Use GetFloat or GetInteger instead. |
GetInteger | Get an integer from the property block. |
GetMatrix | Get a matrix from the property block. |
GetMatrixArray | Get a matrix array from the property block. |
GetTexture | Get a texture from the property block. |
GetVector | Get a vector from the property block. |
GetVectorArray | Get a vector array from the property block. |
HasBuffer | Checks if MaterialPropertyBlock has the ComputeBuffer property with the given name or name ID. To set the property, use SetBuffer. |
HasColor | Checks if MaterialPropertyBlock has the Color property with the given name or name ID. To set the property, use SetColor. |
HasConstantBuffer | Checks if MaterialPropertyBlock has the ConstantBuffer property with the given name or name ID. To set the property, use SetConstantBuffer. |
HasFloat | Checks if MaterialPropertyBlock has the Float property with the given name or name ID. To set the property, use SetFloat. |
HasInt | This method is deprecated. Use HasFloat or HasInteger instead. |
HasInteger | Checks if MaterialPropertyBlock has the Integer property with the given name or name ID. To set the property, use SetInteger. |
HasMatrix | Checks if MaterialPropertyBlock has the Matrix property with the given name or name ID. This also works with the Matrix Array property. To set the property, use SetMatrix. |
HasProperty | Checks if MaterialPropertyBlock has the property with the given name or name ID. To set the property, use one of the Set methods for MaterialPropertyBlock. |
HasTexture | Checks if MaterialPropertyBlock has the Texture property with the given name or name ID. To set the property, use SetTexture. |
HasVector | Checks if MaterialPropertyBlock has the Vector property with the given name or name ID. This also works with the Vector Array property. To set the property, use SetVector. |
SetBuffer | Set a buffer property. |
SetColor | Set a color property. |
SetConstantBuffer | Sets a ComputeBuffer or GraphicsBuffer as a named constant buffer for the MaterialPropertyBlock. |
SetFloat | Set a float property. |
SetFloatArray | Set a float array property. |
SetInt | This method is deprecated. Use SetFloat or SetInteger instead. |
SetInteger | Adds a property to the block. If an integer property with the given name already exists, the old value is replaced. |
SetMatrix | Set a matrix property. |
SetMatrixArray | Set a matrix array property. |
SetTexture | Set a texture property. |
SetVector | Set a vector property. |
SetVectorArray | Set a vector array property. |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.