Need some explanation about collection proxies

Hi there. Just started with Defold, so far it’s quite nice. Love it for the speed of execution and builds. But the topic of collection proxies seem to be a very confusing one. Just bumped into something strange myself and would very much appreciate some clarification.

So I have a loader game object with a collection proxy component and a bunch of scenes I’d like to switch between. I’m using the collectionproxy.set_collection call. to set different collections on the same proxy. Then I do the async_load and listen for proxy_loaded message. If there’s already a collection loaded I check that and do unload, then wait for proxy_unloaded, then do async_load. Every time I get ok status from collectionproxy.set_collection call.

But this doesn’t seem to work unless I add collection proxies with all the collection I’d like to switch to up first. I don’t have to reference them, use them or anything. They just have to be there like so:

If I only use one collection proxy and would like to switch the collection I don’t receive the proxy_loaded when setting a collection other then the one set in the editor. Any ideas? :slight_smile:

Also, is there a way of checking for the collection loading progress in case It might take a while and I’d like to have a progress bar or something? Looking at the specs it looks like maybe get_resources/missing_resources might be the way?

Why? The collectionproxy.set_collection is what I’d call a “power user” feature for developers that download additional game content as part of a dlc of some kind and need to modify existing collection proxies.

If you need to load and unload “scenes” then create one collection proxy per collection and load and unload them. Do not bother with set_collection.

2 Likes

Hey, thank you for such a fast reply :slight_smile: If that is the intended use then that is what I’ll do.

May I also ask how to go about the loader for larger collections loaded through the proxy? I assume that such a collection is loaded into RAM on load/async_load, right? So if it’s resource-heavy (textures and so on) then it may take a while. Also, is it doable to preload some resources? Very sorry if those are newbie questions. Tried to look around the web, but I’ve only found a feature request for something like this (5242). Are there any possibilities here?

So if it’s resource-heavy (textures and so on) then it may take a while

I’d say, step one is to measure if it’s a problem.
I’d recommend using load async, so that you don’t have any stalls on any loading screens.

But yes, it’s generally recommended to only put the resources you need into each collection
(e.g. think “level1”, “level2” and so on), as opposed to loading one mega collection containing all levels.

You are not able to preload a subset of the resources used by a collection proxy, but you can ofc load all of them but not initialise the load collection objects. You can also be more granular about it and async load, then initialise all objects, and then later also enable them. See “init” and “enable”:

1 Like

Great! Thank you for the answers :slight_smile: