Materialpropertyblock



Nov 13th, 2019
Never
Materialpropertyblock
Not a member of Pastebin yet?Sign Up, it unlocks many cool features!
  1. usingSystem.Collections.Generic;
  2. {
  3. MaterialPropertyBlock props;
  4. Renderer[] renderers;
  5. //Animator anim; uncomment if you have an animator attached and a hit animation
  6. void Start()
  7. props =new MaterialPropertyBlock();
  8. renderers = transform.GetComponentsInChildren<Renderer>();
  9. // anim = GetComponent<Animator>(); uncomment if you have an animator attached and a hit animation
  10. }
  11. // Update is called once per frame
  12. {
  13. {
  14. // anim.Play('Hit'); uncomment if you have an animator attached and a hit animation
  15. }
  16. {
  17. for(int i =0; i < renderers.Length; i++)
  18. renderers[i].SetPropertyBlock(props);
  19. yieldreturnnew WaitForSeconds(0.1f);
  20. for(int i =0; i < renderers.Length; i++)
  21. renderers[i].SetPropertyBlock(props);
  22. }

It allows you to easily shove meshes to the GPU, customize them with MaterialPropertyBlock s, and avoid the fat overhead of GameObject s. Additionally, Unity has to do a little less work to figure out if it can instance the objects or not, and will throw an error rather than silently nerfing performance. To override the material's color, we have to provide the object's renderer component with a material property block. Do that by creating a new MaterialPropertyBlock object instance, give it a Color property via its SetColor method, then pass it to the object's MeshRenderer component, by invoking its SetPropertyBlock method. 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. 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'.

RAW Paste Data

Materialpropertyblock

Unity animate material propertyMaterialpropertyblock

Materialpropertyblock Srp