
Unity Time.timeScale Bug: How Pausing Affects Coroutines and Physics
February 13, 2026
Unity Inspector Reference Reset Bug: Why Public Variables Lose Assignments and How to Prevent It
February 13, 2026If 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:
- UI causing unexpected performance spikes
- Frame rate drops when updating text or images
- UI elements flickering or redrawing oddly
- Profiler showing excessive Canvas rebuilds
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.
What Is the Canvas Dirty Flag?
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:
- Modifying text
- Changing an Image sprite
- Resizing a RectTransform
- Changing layout properties
- Enabling or disabling UI elements
The problem happens when too many things mark the Canvas as dirty too often.
Why Performance Drops Happen
When a Canvas is marked dirty, Unity may need to:
- Recalculate layout
- Rebuild vertex buffers
- Regenerate draw calls
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.
Common Scenario 1: Updating Text Every Frame
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.
Common Scenario 2: Large Single Canvas
If all UI elements are placed under one big Canvas, any change forces a rebuild of everything.
This is inefficient.
Better structure:
- Static UI elements on one Canvas
- Frequently updated elements on a separate Canvas
- Popups on their own Canvas
Smaller Canvases mean smaller rebuild costs.
Common Scenario 3: Layout Components Causing Chain Rebuilds
Layout components such as:
- Vertical Layout Group
- Horizontal Layout Group
- Content Size Fitter
- Layout Element
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.
Rendering Artifacts and Flickering
Sometimes developers see flickering or strange visual redraw behavior.
This can happen when:
- UI is rapidly enabled and disabled
- Anchors and pivots are changed frequently
- RectTransforms are modified repeatedly
Rapid structural changes force Unity to rebuild mesh data constantly.
How to Detect the Problem
Use the Unity Profiler:
- Open Profiler
- Look under UI section
- Watch for Canvas.BuildBatch spikes
- Look for Layout.Rebuild entries
If these appear frequently, your UI is being marked dirty too often.
Reliable Fixes
1. Separate Static and Dynamic UI
Keep health bars, timers, and dynamic text on separate Canvases from static backgrounds.
2. Avoid Updating UI Every Frame
Only update UI when data actually changes.
3. Minimize Layout Groups
Use layout components only where necessary. For static layouts, remove them after positioning elements.
4. Disable Raycast Target on Decorative Images
Unnecessary raycast checks can increase UI cost.
5. Use World Space Canvas Carefully
World Space Canvases are more expensive because they behave like 3D objects. Use them only when required.
6. Batch UI Changes Together
If updating multiple UI elements, update them in one function instead of spreading changes across multiple scripts.
Advanced Tip: Manual Canvas Control
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.
Is This Really a Bug?
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.
Conclusion
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.










