Performance: Image and raw image components
This affects how quickly images appear on screen and how smoothly the UI responds during interactions.
Jump into concepts and practice - no test required
Use Image component for sprites and UI elements that use sprite atlases or compressed textures.
Using RawImage for all UI elements regardless of texture type, e.g., RawImage with compressed sprite textures.
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Image component with sprite atlas | Minimal UI elements | None | Low GPU cost due to batching | [OK] Good |
| RawImage with uncompressed textures | More UI elements | None | High GPU cost, no batching | [X] Bad |
Image img = GetComponent<Image>(); img.color = new Color(1, 0, 0, 0.5f);What will be the visible effect on the Image component?
RawImage rawImg = GetComponent<RawImage>(); rawImg.sprite = mySprite;