Search Unity

FileID system in runtime

Discussion in 'Editor & General Support' started by Leonetienne500, Nov 26, 2019.

  1. Leonetienne500

    Leonetienne500

    Joined:
    Dec 5, 2016
    Posts:
    130
    So, i have a large item database. It is about 100000 entries long. Each item has the attribute iconId. There are much less icons than items, since many of them are reused. They are located in ".\icons\<id>.png"

    (The icon ids are not just 1,2,3... They go up to about 50000 and begin an maybe 1000. Although there are much less than 40000 icons.)

    Now, how would i go about loading them in runtime? The folder structure gets obfuscated. I mean, how do i do this efficiently.

    I have two ideas but both are terribly inefficient . I thought about just creating an icon sprite array and to populate it via an editor script.
    This way i would have to iterate through it every time i want an icon... Slow as heck.

    My second idea was to just create a sprite[maxId] array and to populate it along these lines:
    Code (CSharp):
    1. //pseude editor code
    2. for (sprite s in folder "icon")
    3. {
    4.      spriteArr[id] = getFile(s) ;
    5. }
    This way most of the array would just be null values, but i could just call Sprite ico = icons[45219];
    This would be really fast, but kind of memory wasting.
    Sure, i could save maybe a thousand entries by offsetting every id by the smallest id but that would just be a drop in the barrel.

    What do you think?

    EDIT:
    Target platform is android
     
    Last edited: Nov 26, 2019
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,300
    Have you looked at the Addressables system? You could mark each item as addressable and then just use the address to get them. The address could be a unique name, path, guid etc. You can even use labels to filter for various types of icons. The icons can then be packed into asset bundles and loaded only when they are needed.
    https://docs.unity3d.com/Packages/com.unity.addressables@1.4/manual/index.html
     
  3. Leonetienne500

    Leonetienne500

    Joined:
    Dec 5, 2016
    Posts:
    130
    This sounds like it would be just perfect for this!
    Thanks, i will definitely have a look at it!
     
    karl_jones likes this.