Search Unity

Question Loading hundreds of UI images using addressables?

Discussion in 'Addressables' started by BrandStone, Jul 6, 2021.

  1. BrandStone

    BrandStone

    Joined:
    Jul 21, 2014
    Posts:
    79
    I'm not sure if i'm approaching this correctly but I'm working on a card game (like heartstone) and I have a menu section with all the cards the user can unlock (about 230 at the moment).

    Does this mean that I will have to load all those sprites into memory to display them in the list?
    I can surely split them by some categories and preload them separately.

    Has anyone else bumped into a similar situation? Am I on the right track?

    Thanks
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,939
    I think you're on the right track.

    I'm making a survival-craft game that is likely to have loads of items, all of which will have icons, some of which will have meshes/textures, using scriptable objects. Knowing that if assets are referenced directly, they will be loaded into memory once the SO is referenced in a scene; thus should the player walk into the scene that's their home base for example with a storage full of items, you'd have the potential to load hundreds of icons straight into memory, and potentially meshes/materials that don't need to be used at all.

    So I used Addressables for these assets. Each item type has a boolean property that checks if the sprite/mesh/material is loaded, and an async Task method for loading the corresponding asset. So the logic becomes 'Sprite Loaded? If not, load the addressable sprite. If yes, just use what's already loaded'. I wrote extension methods too to make this easier in each different item class, and an extension method to fade in a sprite if it had to be loaded in late via addressables.

    You could very much use a similar approach, depending on how you're storing your card assets (I'm assuming Scriptable Objects because they're awesome.)