I’m working on game where I have many pictures. There are 5 location and 100 enemy images. Issue is that they are used only sparsly. Location img for switching location is used only once in every 20 games or so and out of 100 enemies only 1 is always used at a time so the rest is not used. I always worked with Resources folder to load assets from there but from what I red on unity pages (Assets, Resources and AssetBundles - Unity Learn) it should not be used generally.
They also recommend using AssetBundles (which I never used before), but from what I red on the web, if I put 100 images into AssetBundle, the memory usage will get high as it contains a lot of resources and thus the loading time will take more time. Since I’m making game on android, its crutial to keep loading times at minimum.
Does anybody has any experience handling lot of resouce images/audio files that are nt used so often and if using AssetBundles is the way or if there is other more effective way in sence takt the loading will be faster?
Have you measured your performance problems already? The Profiler would be a start to measure the execution time of your loading code if it’s executed after Awake. Anything before that is more difficult to time, but a simple stopwatch can help.
After profiling, you might realize that loading 100 images is hardly an issue unless you made some big mistake or the images are unreasonably large. The link about best practices for the resources folder mentions, that lookup performance degrades noticeably at around 10.000 objects. This is more of the scale where performance becomes relevant.
In any case, using the resources folder to load one out of 100 images sounds like a good idea. Remember, if you have a list of references to all 100 images in your scene, they all will be loaded at deserialization and therefore remain in memory unless the scene is unloaded. With the resources system, you can load a single image, so this would work for your use-case.
AssetBundles are indeed the way to go for bigger productions. You would try to divide your content into chunks which should be loaded together. Something like “Level13-Assets”, so you can load and unload bundles on demand. As mentioned in the documentation, they have a few other benefits like the ability to download via the web and replace content on the fly. However, putting 100 images into one bundle doesn’t benefit your loading time at all. Creating 100 AssetBundles is also not practicable. Basically, if you don’t have at least several hundred assets, it’s not going to be faster than just loading all references at scene load.
Hence, I would stick to scene references first, then optimize to only load specific files, if performance drops and switch to AssetBundles if the asset count is at least a few hundred.