unity runtime_error ai_generated true

Warning: A different rendering setup is being used for rendering than the one used for instantiating. Batch break.

ID: unity/rendering-batch-break-instantiation

Also available as: JSON · Markdown · 中文
85%Fix Rate
82%Confidence
1Evidence
2023-08-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Unity 2022.3 active
Unity 2023.1 active
Unity 2021.3 active

Root Cause

Material property blocks or shader keywords differ between instantiation and rendering of a GameObject, causing the GPU instancing batch to break.

generic

中文

GameObject 的实例化和渲染之间材质属性块或着色器关键字不同,导致 GPU 实例化批次中断。

Official Documentation

https://docs.unity3d.com/Manual/GPUInstancing.html

Workarounds

  1. 80% success Ensure all instanced objects use the same MaterialPropertyBlock values by assigning them in a single batch: `MaterialPropertyBlock block = new MaterialPropertyBlock(); renderer.GetPropertyBlock(block); block.SetColor("_Color", Color.red); renderer.SetPropertyBlock(block);`
    Ensure all instanced objects use the same MaterialPropertyBlock values by assigning them in a single batch: `MaterialPropertyBlock block = new MaterialPropertyBlock(); renderer.GetPropertyBlock(block); block.SetColor("_Color", Color.red); renderer.SetPropertyBlock(block);`
  2. 75% success Disable per-instance shader keywords by removing `#pragma multi_compile` variants that vary per object, or use `Shader.EnableKeyword` globally.
    Disable per-instance shader keywords by removing `#pragma multi_compile` variants that vary per object, or use `Shader.EnableKeyword` globally.
  3. 85% success Use `Graphics.DrawMeshInstanced` with a shared material and property block array instead of individual renderers.
    Use `Graphics.DrawMeshInstanced` with a shared material and property block array instead of individual renderers.

中文步骤

  1. Ensure all instanced objects use the same MaterialPropertyBlock values by assigning them in a single batch: `MaterialPropertyBlock block = new MaterialPropertyBlock(); renderer.GetPropertyBlock(block); block.SetColor("_Color", Color.red); renderer.SetPropertyBlock(block);`
  2. Disable per-instance shader keywords by removing `#pragma multi_compile` variants that vary per object, or use `Shader.EnableKeyword` globally.
  3. Use `Graphics.DrawMeshInstanced` with a shared material and property block array instead of individual renderers.

Dead Ends

Common approaches that don't work:

  1. 40% fail

    Disabling GPU instancing globally reduces performance and doesn't address the root cause of property block mismatch.

  2. 60% fail

    Setting material.renderQueue manually often ignores the underlying shader property block differences.

  3. 50% fail

    Using MaterialPropertyBlock.Clear() before every draw call may cause flickering and still not synchronize with instancing.