

If your Unity UI suddenly causes frame drops, strange redraw behavior, or visual glitches, you may be dealing with what developers often call the “Canvas Dirty Flag bug.”
The issue usually appears as:
This is not exactly a bug in Unity. It is usually caused by how the Canvas dirty system works internally. Once you understand it, the problem becomes much easier to fix.
Unity’s UI system uses a “dirty flag” system to know when it needs to rebuild or redraw parts of the Canvas.
When something changes in the UI, Unity marks the Canvas as “dirty.” On the next update cycle, it rebuilds the affected elements.
Changes that trigger a dirty state include:
The problem happens when too many things mark the Canvas as dirty too often.
When a Canvas is marked dirty, Unity may need to:
If your entire UI is on a single Canvas and one small element changes, the whole Canvas can be rebuilt.
This is where performance issues begin.
One of the most common causes is updating a Text component inside Update().
Example:
void Update()
{
scoreText.text = score.ToString();
}
This marks the Canvas dirty every frame, even if the value does not change.
Better approach:
private int lastScore;
void Update()
{
if (score != lastScore)
{
scoreText.text = score.ToString();
lastScore = score;
}
}
Only update when necessary.
If all UI elements are placed under one big Canvas, any change forces a rebuild of everything.
This is inefficient.
Better structure:
Smaller Canvases mean smaller rebuild costs.
Layout components such as:
can cause cascading layout rebuilds when one element changes.
This often results in repeated dirty flag triggers in a single frame.
If performance drops when modifying UI dynamically, check layout components first.
Sometimes developers see flickering or strange visual redraw behavior.
This can happen when:
Rapid structural changes force Unity to rebuild mesh data constantly.
Use the Unity Profiler:
If these appear frequently, your UI is being marked dirty too often.
Keep health bars, timers, and dynamic text on separate Canvases from static backgrounds.
Only update UI when data actually changes.
Use layout components only where necessary. For static layouts, remove them after positioning elements.
Unnecessary raycast checks can increase UI cost.
World Space Canvases are more expensive because they behave like 3D objects. Use them only when required.
If updating multiple UI elements, update them in one function instead of spreading changes across multiple scripts.
In rare cases, you can temporarily disable the Canvas while making bulk changes.
canvas.enabled = false; // Make multiple UI changes here canvas.enabled = true;
This reduces repeated rebuilds during large updates.
Most of the time, no. The dirty flag system is working as designed. The issue comes from how often developers trigger UI changes without realizing the cost.
Once UI is structured properly, performance becomes stable and rendering artifacts disappear.
The Unity Canvas dirty flag issue is usually a design problem, not an engine flaw. Excessive UI updates, large single Canvases, and layout rebuild chains are the real causes.
By separating dynamic and static UI, reducing unnecessary updates, and profiling regularly, you can eliminate performance spikes and rendering artifacts.
UI performance in Unity depends heavily on structure. A well-organized Canvas hierarchy makes a huge difference.