Loading assets when needed (dynamically)

I am working on a project with about ~30MB of soundfiles. The game will run in browser, so I want to load as few resources as possible, it is not plausible for me to load all of this data in one go. Especially since not all of it will be necessary in every game session.

The game is easily divided into parts, where each one could load assets specific to that one. However, I can not figure out how to do this. For example: On boot all general sounds would be loaded and menu music. When starting the first level, that would load the music and sound effects specific to that one. I thought Collection proxy would be the way to go, but all assets still seem to load at once when booting.

If this question has already been answered, please tell me where, I couldn’t find anything.

2 Likes

Unfortunately I do not think this is currently possible. You can load external files, but externally loaded sounds can’t be prepared to work on the fly, which should probably be a feature request if it isn’t already.

If your game is meant to be a webgame only then perhaps play the music files on the page more directly outside of the game.

You are correct about all assets downloading at one. They are all bundled into a single archive blob which is downloaded all at once.

Maybe another feature request would be to able to prepare and load files from other game archive blobs more easily. For example, being able to specify a flag on a collection which says it should be bundled into another named blob. Then collections can be saved either in the main blob by default, or sorted into whatever other blobs they are set for, which are then loaded all at once (with async and ready signals) as anything within then is accessed.

1 Like

Oh, that’s quite sad for me. Was really looking forward to using Defold. The amount of sound I have to load will grow a lot for me because it is speech and it will be localized in a couple of different languages.

Thanks for your answer, it was exactly the question I wanted answers to. Too bad it wasn’t what I hoped it would be… Anyway I do hope that this will make it into the game engine, then I’ll be back!

1 Like

I’ve made the feature requests so we’ll see!

2 Likes

These are strong King-internal requirements as well, so it’s just a matter of time before we need to have them fixed. Unfortunately I have no idea when they will be done, but you should check back in two months or so!

5 Likes

Being able to load assets, especially sound, dynamically during run-time is a very appealing feature. Looking forward to see what comes of this!

2 Likes

As Ragnar said, this is a very highly requested feature from some teams within King. Having a small initial download for a game on Facebook for instance is very important in countries where internet connections are slow.

4 Likes

Any update on this, guys?

You can use the live update system to load parts of your game at runtime.