By Oxide


2019-04-12 09:03:36 8 Comments

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?

2 comments

@Shuvro Sarkar 2019-04-12 20:02:46

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.

When you install Addressables, your asset will have a new checkbox in the inspector to mark that as an addressable. You just mark all the assets you want to load on runtime. Then from the Addressable's window (Window-> Asset Management->Addressable Assets), you can group assets, label them, and put the downloadable address for each group. (So you can either make 5000 assets as one group, make 10 groups (500 assets each) and then put the host address where you want to download it from runtime.

Here are a few links to getting started with Addressable.

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

2. Addressables-Sample

3. Unite Melbourne- Hands on Session on Addressable Assets

@Philipp 2019-04-12 10:19:13

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().

Putting each sprite into its own asset bundle might be one posible solution. But I have never worked with a project with 5000 asset bundles before, so I am not sure if this solution is really that scalable. If you can, try to group your asset bundles into what you are going to need at the same time. For example, if you have a 1:n relationship between areas and monsters, try to put all the monsters for one area into one asset bundle. But now you do of course need some kind of directory system which tells you which monster is in which asset file (with each monster in its own file, you can just name the files after the technical identifiers of your monsters).

I am looking forward to defeating all the 5000+ monsters in your game.

@gjh33 2019-04-12 13:28:35

I would recommend Adressables. AssetBundle is a really difficult to maintain system. It's another layer of organization you have to remember to constantly keep up to date. I've had to work with it for several titles and it's one of the most infuriating APIs. Every version of the doc tells you something different as the API has changed rapidly over time, and the real answer is some combination of all the docs. It's why they made Adressables.

@Philipp 2019-04-12 13:33:55

@gjh33 I haven't heard about that feature yet. Maybe you would like to write an own answer where you explain this in detail?

@gjh33 2019-04-12 13:38:21

The reason I don't is because I haven't worked with it. I have however worked with AssetBundles quite a bit, both loading from disk and loading over the web for a WebGL port. It might be a Unity 2019 feature, but I'll link it and let poster decide if he wants to use it. The other project team is using it, and have found it pretty useful. Here's a link to the doc: docs.unity3d.com/Packages/[email protected]/manual/‌​…

@Galandil 2019-04-13 17:54:39

AFAIK, Addressables are a workflow system, easier to use and maintain compared to Asset Bundles, but under the hood they're still Asset Bundles. A Unity dev suggested to a user in the forums to use Addressables if the project on which you're working is to be shipped in the second half of 2019, or later. They can be used from version 2018.2.

Related Questions

Sponsored Content

2 Answered Questions

[SOLVED] Webgl page heap size increasing in each page load then crash

  • 2019-03-16 10:55:10
  • Muhammad Faizan Khan
  • 124 View
  • 2 Score
  • 2 Answer
  • Tags:   unity webgl

0 Answered Questions

What are efficient strategies to support alternate spritesheets in Unity

  • 2018-11-19 20:06:02
  • jwatkins
  • 29 View
  • 1 Score
  • 0 Answer
  • Tags:   unity spritesheet

0 Answered Questions

How should I organize 2D sprites?

  • 2018-10-14 21:30:32
  • Ben Rubin
  • 112 View
  • 2 Score
  • 0 Answer
  • Tags:   unity

2 Answered Questions

[SOLVED] Loading encounters and collisions questions within 2D

  • 2018-05-01 09:01:52
  • John Cogan
  • 32 View
  • 0 Score
  • 2 Answer
  • Tags:   unity 2d open-world

2 Answered Questions

[SOLVED] Unity: SpritePacker Atlas with Dynamic Access

  • 2017-08-10 10:24:36
  • Engineer
  • 717 View
  • 1 Score
  • 2 Answer
  • Tags:   unity loading

1 Answered Questions

[SOLVED] How do I run code for a period of time and then return to normal behavior?

  • 2016-12-28 17:31:53
  • Mohit Saxena
  • 150 View
  • 0 Score
  • 1 Answer
  • Tags:   unity c#

3 Answered Questions

[SOLVED] Are loading screens more important than they appear to be?

  • 2016-07-07 06:13:23
  • Danny
  • 548 View
  • 2 Score
  • 3 Answer
  • Tags:   unity game-design

1 Answered Questions

[SOLVED] Performance Optimization for 2D game developed using Unity 3D game engine

  • 2016-04-01 09:46:09
  • Daniyal Azram
  • 371 View
  • 0 Score
  • 1 Answer
  • Tags:   unity

1 Answered Questions

1 Answered Questions

[SOLVED] Unity 2D Graphics Optimization For Mobile Devices

Sponsored Content