unity runtime_error ai_generated true

ArgumentException: Command buffer overflow. Cannot push more commands. The maximum capacity is 2048.

ID: unity/rendering-command-buffer-overflow

Also available as: JSON · Markdown · 中文
82%Fix Rate
88%Confidence
1Evidence
2023-09-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2021.3 active
2022.3 active
2023.2 active

Root Cause

A script or shader pushes too many commands into a CommandBuffer, exceeding the default capacity of 2048 commands.

generic

中文

脚本或着色器向命令缓冲区推送了过多命令,超出默认容量2048。

Official Documentation

https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.html

Workarounds

  1. 90% success Batch commands using CommandBuffer.Clear before pushing new ones. For example, in an Update loop, call cmdBuffer.Clear() at the start of each frame and rebuild only necessary commands.
    Batch commands using CommandBuffer.Clear before pushing new ones. For example, in an Update loop, call cmdBuffer.Clear() at the start of each frame and rebuild only necessary commands.
  2. 85% success Reduce command count by merging draw calls with MaterialPropertyBlock or using GPU instancing. Replace per-object draw calls with a single DrawMeshInstanced.
    Reduce command count by merging draw calls with MaterialPropertyBlock or using GPU instancing. Replace per-object draw calls with a single DrawMeshInstanced.
  3. 60% success Set CommandBuffer's maximum capacity via reflection (not recommended for production) or offload some commands to a compute shader.
    Set CommandBuffer's maximum capacity via reflection (not recommended for production) or offload some commands to a compute shader.

中文步骤

  1. Batch commands using CommandBuffer.Clear before pushing new ones. For example, in an Update loop, call cmdBuffer.Clear() at the start of each frame and rebuild only necessary commands.
  2. Reduce command count by merging draw calls with MaterialPropertyBlock or using GPU instancing. Replace per-object draw calls with a single DrawMeshInstanced.
  3. Set CommandBuffer's maximum capacity via reflection (not recommended for production) or offload some commands to a compute shader.

Dead Ends

Common approaches that don't work:

  1. 90% fail

    CommandBuffer capacity is hardcoded internally; no public API exists to change it. Attempting to do so causes compilation errors.

  2. 50% fail

    Removing CommandBuffers may break custom rendering effects like outlines or post-processing.

  3. 70% fail

    Changing pipeline requires rewriting shaders and materials, which is a large refactor and may not resolve buffer overflow.