Materialpropertyblock

  

Hi, I wanna change the texture of my spine animations, with this forum's advice I made it work by using MaterialPropertyBlock. But some animations not working properly, some parts of its attachments are not replaced with the new texture. 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. Submission 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. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. To refresh your session. You can do this with a MaterialPropertyBlock, just like you would in the old pipeline to reduce the overhead of instantiating modified copies of materials. The only difference is that the shader property is called 'BaseColor' not 'Color'.

Sample of the Unity MaterialPropertyBlock Problem

I create this project just to show the problem that I have when a gameobject has an Animation colour and after that I want to change the material color but this not work.

What is inside

GameObject (Cube)

Materialpropertyblock

Materialpropertyblock Keyword

Perrendererdata

This cube has an animator and a clip called AnimColor that generate a transition between 2 colours

Material

Script (Player)

  • Startwhen start change the cube colour This is the problem the colour never change

  • Updatewhen user press and hold the key space change the state to AnimColor

How to make it work

Materialpropertyblock

Just select the Cube and uncheck the Animator, now when start the game the colour of cube is RED 😡

Materialpropertyblock Urp

MaterialPropertyBlock Class
  • Menu
  • MaterialPropertyBlock

A block of material values to apply.

MaterialPropertyBlock is used by Graphics.DrawMesh. 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.

Materialpropertyblock Texture Offset

For performance reasons, the property block can contain only a limited number of property values. Two 4x4 matrices, six vectors/colors or 12 floats can be stored in the block. Storage space for the values is shared, so storing one matrix leaves twice less space to store vectors and floats.

Graphics.DrawMesh copies the passed property block, 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.

Unity Animate Material Property

See Also:Graphics.DrawMesh, Material.

Materialpropertyblock Shader Graph

AddFloat

Add a float material property.

AddVector

Add a vector material property.

AddColor

Add a color material property.

AddMatrix

Add a matrix material property.

Clear

Clear material property values.