# What am I suppose to use instead of Unity Resources if I have to load and unload sprites at runtime?

I recently read this guide posted in the Unity website about Resources. It is clear from the get-go that it is discouraged to use Resources unless you are prototyping something.

My game is like a 2D RPG, and it has over five thousand monster sprites (yes, a lot). As far as I'm concerned, it makes perfect sense to put all the sprites in the Resources folder, and just load the ones that I need (using their name) when a battle starts and then unload them.

The Unity article makes one point that might support my approach:

Generally required throughout a project's lifetime

Well, I'm not so sure about it - in a single game session it's entirely possible that thousands of those sprites will not be used at all as the player simply doesn't encounter those monsters.

The article goes on to talk about why is it discouraged to use Resources:

This operation is unskippable and occurs at application startup time while the initial non-interactive splash screen is displayed. Initializing a Resources system containing 10,000 assets has been observed to consume multiple seconds on low-end mobile devices, even though most of the Objects contained in Resources folders are rarely actually needed to load into an application's first scene.

And it is indeed true - my game does in fact take several seconds to load on some low-end devices, especially Android ones. It is also true that none of those sprites of mine need to be loaded at startup.

So I am willing to stop using Resources - but I am at a loss now: the article doesn't mention a reasonable alternative to this.

Here are the (unreasonable) approaches that I have thought of:

Create a component with a collection of all the sprites, that way they are all loaded without using Resources.

Yeah but I have five thousand sprites. This sounds extremely tedious.

Same as the previous suggestion, but use Texture Packer or something similar to pack lots of sprites into different sheets - this way I have to do less work.

My sprites are large and packing them won't be a huge help - I'd still end up with a thousand or so sheets.

My point is, I just can't have 5000+ sprites preloaded. I need to load them at runtime via Resources, but Unity clearly discourages it. Is there a solution to this?

• Are all those 5000+ monsters really unique? If any of them are just palette swaps of each other then I would recommend to use the same sprite asset and do the recoloring at runtime using a sprite shader. – Philipp Apr 12 at 12:56

Well, there are currently two other ways(other than using Resources Folder) to maintain assets in unity.

1. Asset Bundle, like @Phillipp mentioned. (Get Started with AssetBundle Here)

2. Addressable: Its a new feature in Unity 2018+. You can simply grab the package through unity's package manager. One thing to note here is Addressables are now in beta. So, many people will not recommend it. However, I used it for one of my projects and it works fine.

1. Unity's Addressable Asset system for speed and performance - Unite LA

If you want to load assets at runtime, then the solution suggested by Unity Technologies is to put those assets into asset bundle files which you can then load at runtime with AssetBundle.LoadFromFile(filepath). When you don't need the sprite anymore, unload that asset bundle with loadedAssetBundle.Unload().