I was reading a blog from Unity about UI it has a term like component is dirty, what does that mean component is dirty ?

Unity UI Fundamentals tutorial


Without context it's hard to say for sure, but "dirty" in programming generally means that an object has been modified, but those changes have not yet been propagated out to related data structures or systems.

This is generally an optimization technique. By using dirty checks, a system can avoid repeatedly processing redundant state changes (e.g., making sure only the most recent change is processed each frame for objects that may be updated many times during the frame). There's some additional performance benefits and pitfalls with dirty flags as well.

For something like a UI component, I would imagine this has to do with UI rendering. The UI renderer may not want to recalculate text width or redraw overlay textures if nothing has changed, so it instead checks to see if any observed UI components are "dirty" before doing its more expensive updates.


Sean gave a great answer for general usage of the term. Specifically with regards to Unity UI, a canvas (component) is marked as dirty whenever there is a change to one of its constituent meshes.

Here's the official, more detailed explanation:

A Canvas is a native-code Unity component that is used by Unity’s rendering system to provide layered geometry that will be drawn in, or on top of, a game’s world-space.

Canvases are responsible for combining their constituent geometry into batches, generating the appropriate render commands and sending these to Unity’s Graphics system. All of this is done in native C++ code, and is called a rebatch or a batch build. When a Canvas has been marked as containing geometry that requires rebatching, the Canvas is considered dirty.

Additional details about how this affects the rendering process can be found in the Fundamentals of Unity UI best practices tutorial.

  • 2
    \$\begingroup\$ The better answer since it's specific to the given context. :) \$\endgroup\$ Jul 6 '18 at 6:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .