Use different sprites in new Unity UI for SD vs HD

Hi all,

We are looking at the new Unity UI coming from using NGUI.
Looking at the documentation for the Canvas Scaler and Designing UI for Multiple resolutions, I understand how to set the layout for my UI components and how to get them to scale properly.

One thing I am unclear on however is the ability to specify a different set of images depending on the resolution (SD vs HD), similar to what NGUI provides with Reference Atlases.

We want to load different sprites (or sprite atlases) depending on the supported resolution for the device. Two reasons: (1) on higher resolution devices we want pixel perfect images (larger images) but (2) on lower resolution devices we want to use as little memory as possible (since lower res devices tend to also be lower RAM)


It seems the Canvas Scaler only allow us to either (a) provide large textures scaled down for lower resolution devices (correct visuals but larger memory footprint) or (b) provide small textures scaled up on higher resolution devices (lower memory footprint but scaling artifacts)

I haven’t seen any documentation that addresses this topic specifically. Is there a way to do this?



You might want to use Asset bundles: Unity - Manual: AssetBundles

I did not test the code below, but it should be close to what you need. Create a script and attach to each UI component. Assign the HdSprite in the inspector.

public Sprite HdSprite;
void Start()
    if (Screen.width > 800)
        this.GetComponent<Image>().sprite = HdSprite;

You should check out if you haven’t seen it yet. He begins discussing it in the first few minutes. I am going through the same process as you deciding to try the Unity UI/2D for our next project or stick with our NGui / 2D toolkit approach. I would love to come up with a solution using the native Unity tools, but I am currently leaning towards just using 2D toolkit for everything, including UI.