Best method for asset handling? IE, graphics / sounds to load, etc

In my game menu, each level has a preview image attached, so that from the level select screen, players can see what level they’re about to play. Because there’s colour blind options, I also have 2 other colour blind versions, of each preview, for each level. That’s a lot of images to load.

Initially, I had them all as public variables within a single menu scene, and it wasn’t a problem. But, as the game grew, and I added more levels, I noticed a slight pause, which then became a longer and longer pause, when going from the title screen to the main menu. I believe this was because it was trying to load all of the level previews at once, even though it didn’t need them all yet.

A friend suggested putting them all in the resources folder, which I did, and separated out each menu screen into a prefab, which did improve the speed at which the main menu loaded. However, since then, the game takes noticeably longer to boot, and I think this is the cause. It used to boot very quick.

So, what is the best way to handle this kind of asset management? How can you have a bunch of assets like images, or even sounds, ready to use, but without loading them all into memory and causing slow down, or having the resources folder cause other issues like with boot time?

I pondered using scriptable objects, but I’m not sure if it will cause the same issue that public variables do? How do people get around this? Is there some other way to have them on hand, that’s efficient, and not load them until you need them?

Nice art style! Cannon Fodder meets japanese RPG kind-of. I like it. :slight_smile:

The keywords is: Asset Bundles.
Particularly for color-blind variants it makes sense to have an asset bundle variant so that you only either load the normal or the color blind assets.

But it also matters a lot how and when you load and unload resources. Async loading sounds like something you should consider for your menu, so that only the selected level asset needs to be loaded synchronously while the rest is queued up and likely available when the user clicks on it. You could also limit loading level previews that are within the current scrollview, and as you move that, async load the new ones and unload those out of view.

And how assets are prepared on the editor side of things matters a lot too. For instance, if you have a sprite for each tile but don’t create a spritesheet, this will take a lot longer to load and will be slower to render at runtime too.

And then there are various compression options for textures and other assets like meshes, audio.
And the strategies depend on the platform, ie how fast it can load or decompress assets and how much memory is available and so on.

Your game looks beautiful with that thick saturated color style and all the little pixel shapes.

As CodeSmile notes, lots of options.

Personally I like Resources.Load() and LoadAll() but you have to be careful using them because they have a few gotchas. For instance, if you fail to supply the portion, Unity will load ALL the things in your filespec rather than just the type you want.

The main point about any given resource (ScriptableObject, Prefab, whatever) is that when you load it, Unity will also load 100% of everything that it points to. So if you have a LevelDefinition ScriptableObject instance and it has three variants of an image, all of them will load.

Another option is to demand-load some of this stuff too… for instance the main menu might not need ALL images loaded at full resolution. You could make lower-resolution ones that ARE included in the main menu, but when selected they briefly show the low-res version, then stream in the high res versions and replace it.

There are other more string-based asset reference solutions, and by using clever editor scripting you can make string-based asset references almost as bulletproof as actually dragging them in. But this requires some editor scripting. :slight_smile:

And the latest reference way to do Asset Bundles (which still work fine on their own) is by using the Unity Addressables system. I find it a bit cumbersome but I can see where it would be helpful once you reach a certain scale, and it could possibly be that you are at that scale now.

Thank you very much! I’m pleased to meet someone else who remembers Cannon Fodder XD

As far as asset bundles goes, that sounds like a great area to look into.

I might look at compression again, but I noticed it could throw out the colours or pixel crispness / quality at times, so was having trouble finding the best settings - aside from setting the size of the texture as small as possible.

Thank you, I’m glad you like how it looks!

There are many things here to consider about optimizations, thank you. My game seems to have grown quite large in terms of number of assets so I think I probably will need to look into it. Especially when my next game is probably going to be an RPG, I should learn now.

I’m wondering - my level previews are 371 x 232 pixels. A world contains up to 8 previews. I wonder if it would make much difference, in terms of optimization, if I made a sprite sheet of all the previews of a world? vs just leaving them as individual images?

I assume it comes down to the cost benefit of, is it faster to load a few larger files, than lots of smaller files? I really don’t know the benefits here.

I will guess such a thing wouldn’t make much difference.

I would suggest organizing your stuff as cleanly and simply and most straightforward that you can, just for your sake!

I like simplicity personally, every thing sort of on its own, unrelated to other stuff any more than it must be.

Meanwhile, you actually can measure it with the profiler:

And there’s also the Frame Debugger:

https://docs.unity3d.com/Manual/FrameDebugger.html

Don’t forget to consider final binary size if you’re targeting asset stores too.