[DOTS Instancing] MaterialPropertyBlock Batching Failure with URP
Under Audit
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.
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).
- Leverage
Graphics.DrawMeshInstancedorGraphics.DrawMeshInstancedIndirectfor 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 forURPto define and pass per-instance data efficiently.
Editor's Note:
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.