To be honest I don’t know what exactly the Collection Factory 'load'
and 'unload'
function do, I’ve never needed them, but I don’t think they’re for destroying your spawned objects. Also note, the docs say:
“Calling this function when the factory is not marked as dynamic loading does nothing.”
In other words, if you didn’t check the “Load Dynamically” property on the Collection Factory, then there is no reason for you to use those functions.
I think there’s still some misunderstanding here about the difference between a Collection Proxy and a Collection Factory.
For loading your whole game, or the current “level”, you should be using a Collection Proxy—each one has its own physics world, can be paused, reloaded, etc. It’s sort of like having another game running inside your game that you can load and unload at will.
A Collection Factory is just like a regular Factory—it’s for spawning objects (bullets, enemies, players, etc.), only it can spawn a Collection of multiple game objects instead of only a single game object at once.
If you unload a Collection Proxy, everything inside it will be destroyed. If something was not destroyed, that means it wasn’t inside the proxy collection. Maybe it was data that was stored in a Lua module, or an object or script that was actually in the main collection, not the proxy collection. You can use:
print(msg.url())
To check where your objects are (the text before the “:”). For example: “[main:/root#game_manager]” is in my “main” collection, “[level 1:/player/root#player]” is inside my “level 1” collection, which is loaded with a Collection Proxy (therefore my player will be deleted when I unload the Proxy).
Note that unloading doesn’t happen instantly. I believe it will take 1 frame, minimum. This is why you get a “proxy_unloaded” message, so you can tell when it’s done.