Search Unity

Downsides to using RawImage over Image?

Discussion in 'UGUI & TextMesh Pro' started by lumoconnor, Jan 17, 2019.

  1. lumoconnor

    lumoconnor

    Joined:
    Jan 17, 2016
    Posts:
    27
    Hey everyone,

    I've recently switched over from using Image components in my UI to RawImage because I need to create these images dynamically, and using Sprite.Create() to initialise the Image components was slow.

    I was wondering if there were any downsides to making this switch. The documentation mentions something about increasing draw calls, but if each of my Sprites had been using a different texture it would be exactly the same right?

    The only real practical downside I've run into is having to manually scale the RawImages to fit into a parent Rect, while maintaining aspect ratio.

    Any help appreciated. Thanks!
     
    Novack likes this.
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    Yep, but Unity makes it enormously easy to create an atlas of all your individual sprite textures (at edit time), which then again might yield better draw-call batching.
     
    Novack likes this.
  3. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    So, yes: It is pretty much the same if you are using one sprite per texture. Actually, raw images might be even slightly faster than images, but it is such a little difference that it doesn't count.

    For Textures you are creating on the fly and change often, the raw image is better suited because you don't have to make sprites out of it as you stated.
    But in general it is a good idea to use sprite sheets (also called "sprite atlas" or "texture atlas") because then you only need one texture for several sprites and the graphics card has an easier job because it doesn't have to swap textures all the time (results in better performance).

    So, it always depends on the use case. if you have a render texture where a 3D scene is rendered into it for example and you want to display this inside the UI, RawImage is perfect for it.

    But if you are creating textures on loading time once without later change and reuse them, it is better to put them all together in one big sprite sheet instead. I didn't use it yet, but maybe unity's Sprite Atlas can help you here.

    regarding your aspect ratio problem: I would add an aspect ratio fitter component and set the aspect ratio via code, instead of editing the exact size.
     
  4. lumoconnor

    lumoconnor

    Joined:
    Jan 17, 2016
    Posts:
    27
    Thanks folks, appreciate the help. For our purposes then, where images are being downloaded from the web at runtime, it seems like RawImage is the way to go for now, with the caveat that we should consider limiting the number of images that are being rendered at any given time.

    Thanks!
     
    Novack likes this.