Collection Proxy questions: Usage and Performance

I’ve recently started learning more about collection proxies while exploring Defold. I found an older YouTube video explaining them, and I have to say it was excellent. I really hope the Defold team considers making more videos like that in the future.

I started by creating a simple loader that loads and unloads collections through collection proxies depending on what the game needs. For example, it initially loads the main menu collection, and when the player starts the game it unloads the main menu, then loads, initializes, and enables the gameplay collection. As far as I understand, this is a correct and intended use of collection proxies.

Now I’m considering using another collection proxy for my game’s pause menu, but I’m not sure whether that’s the right approach.

The pause menu itself is fairly simple: it only contains a GUI with a few buttons and options. My idea was to load, initialize, enable, and later unload the pause menu collection every time the player presses the pause button. This would all be handled through messages sent to the same main loader that already manages all my collection proxies.

What I’m struggling to understand is whether this is actually the recommended approach, or if it’s an unnecessary complication. Would it be perfectly fine to simply keep the pause GUI inside the gameplay collection and enable/disable it when needed instead?

In short, does repeatedly loading, initializing, enabling, and unloading the same collection have any noticeable performance cost? A player could technically pause and resume the game many times during a single play session, so I’m wondering whether that pattern should generally be avoided.

I also have another question: Is there a recommended way to display two collection proxies on screen at the same time, one on top of the other? I’m not referring to GUI components, since those seem to render on top of everything else without any issues.

If I understand correctly, each collection proxy is created as its own separate world. Because of that, if I keep two collection proxies enabled simultaneously, I wouldn’t be able to use the camera from one collection to render the game objects belonging to the other collection proxy. Is my understanding correct?
If so, is there a Defold-recommended pattern or best practice for handling situations where two collection proxies need to be visible at the same time? I think this version reads naturally for native English speakers while keeping the technical terminology that Defold developers commonly use (e.g. load/unload, initialize, enable, world, and collection proxy). Note that I used unload* onsistently instead of download, matching Defold terminology.

1 Like

Your current setup sounds perfectly reasonable. Having a small persistent loader collection and using collection proxies to switch between the main menu and gameplay is one of the intended uses of collection proxies (e.g. look at Monarch - it solves screen managing this way).

For a small menu, I would probably not load and unload it every time. Keeping it loaded in the same collection (even in the same GUI) and only enabling/disabling it will be simpler and make opening the menu immediate. I do so sometimes for very small popups.

That said, using a proxy for a popup is not an unusual pattern either. Mentioned Monarch, for example, represents screens as collections loaded through collection proxies and also supports popup screens this way. So a separate pause-menu proxy is completely reasonable - especially if you want a clean screen-management architecture, and if you want to pause the game using engine time step, which is a very common approach :wink: I recommend also this video.

Regarding rendering: proxy collections are separate worlds for lifecycle, physics and direct game-object access, but they still submit their visual components to the same render pipeline. A camera is therefore not limited to rendering objects from its own proxy world. The render script can select a camera and then draw any matching render predicates.

What is not automatic is the layering between collections. If two proxy worlds must be visible together, control their order through the render script, material tags and render predicates. For a normal pause menu, GUI rendering already handles this well, so you usually do not need a custom solution.

4 Likes

Thanks a lot for your reply!

I’ll definitely keep your advice in mind, and for this simple game I think I’ll go with a pause menu implemented as a GUI in the same collection as the game world.

I also watched the tutorial video you recommended, and it left me with one small question (maybe @Asatte can answer this as well). In the video, the pause menu GUI is placed directly inside the level’s collection. At the same time, the level is paused by changing the collection proxy’s time step.
Is that actually the correct approach? Since the GUI is part of the same collection, wouldn’t it also be affected by the time step? For example, if the GUI contained animations, would those be paused as well?

As for rendering, I’m going to start by reading the Rendering section of the Defold manual. The idea of displaying multiple collection proxies on screen with the same camera and controlling their rendering order sounds really interesting. If anyone has any tips, articles, or tutorials on the subject, I’d love to hear about them. Anything that helps expand my understanding is always greatly appreciated.

1 Like

Since with the tutorial my goal was showing a basic example, I did not add any animations to it. But, yes. They would actually stop being played since animation fps is calculated by the frames of its collection which we just stopped. My approach to solving this would be creating a separate collection proxy for the pause menu, load it from scene_manager when loading a level that requires a pause screen (all scenes except menu and game over screen probably). This way, I would only set the time_step of the game collection and pause menu would continue being played (you can also stop pause menu when the game is running so that its animations will only be played if game is paused and save a bit of resources)

2 Likes

Thanks a lot for the clarification!

Indeed, if you want to alter the time_step using a collection proxy for something like a pause menu, without constantly loading and unloading it, the only sensible solution is to create it alongside the level and keep it loaded throughout the game, enabling and disabling it as needed.

Of course, this only makes sense if the menu isn’t overly complex. Otherwise, I think Pawel’s simpler approach of using a straightforward GUI within the level’s collection is the best and most performant solution, as it avoids loading all the extra overhead of a collection proxy into memory. I hope that makes sense and that I haven’t got anything wrong!

While I’m here, I have one final question: If I were to use the collection proxy approach for menus as well, and I want to keep things safe (by “safe” I mean, for example, if I need to send a disable message to the proxy, but due to a code bug it’s already disabled), are there any functions or ways to check the status of a Collection Proxy?
More specifically: Does the collection proxy exist? Is it loaded? Is it currently enabled or disabled?

Thanks again! :blush: