UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

graphics

[DOTS Instancing] MaterialPropertyBlock Batching Failure with URP

Under Audit

urp

Unity 2021.3.x - Unity 2023.3.x

Published Wed, Mar 18

Changing individual object material properties using MaterialPropertyBlock with DOTS Instancing can disrupt batching, impacting performance in URP projects.

Issue

 When attempting to modify material properties for individual objects that are configured for DOTS Instancing, applying a MaterialPropertyBlock to a MeshRenderer via SetPropertyBlock() leads to a breakdown in batching. Specifically, setting properties such as _Color or _RimColor results in unbatched draw calls. If no MaterialPropertyBlock manipulations are performed, batching operates as expected across all objects. The documentation for DOTS Instancing shaders lacks explicit C# code examples demonstrating how to change per-instance material properties while preserving batching. This issue has been observed in projects utilizing the Universal Render Pipeline (URP).

Experimental Fixes
  • Leverage Graphics.DrawMeshInstanced or Graphics.DrawMeshInstancedIndirect for explicit instanced drawing, passing arrays of MaterialPropertyBlock values or custom buffers directly.
  • Verify that your custom shader is specifically designed for DOTS Instancing, making sure per-instance properties are declared correctly within the shader code to allow unique values without breaking batching.
  • Explore using the Shader Graph’s ‘Instanced Properties’ feature for URP to define and pass per-instance data efficiently.

Editor's Note:

The above fixes have not been verified by our audit team yet. They are provided exclusively for your own technical research. We recommend creating a backup of your project before proceeding with any attempts. Utilize at your own discretion!

Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.