Just seeing if I’ve got this straight;
- Collection factories will either have their assets preloaded, or load their assets on first spawn, but will not unload their assets when the collection objects are all deleted
- Collection proxies will properly unload their assets when you unload their world - and they are also a way of seperating worlds.
So if I have different level themes like snow and lava, I want those levels and their atlases to be their own collection proxy, so we don’t have every theme in the whole game in RAM at once, just the one for the current level.
The tricky bit is - scripts can’t cross world boundaries.
Intuitively I would want:
- Gameplay collection, spawned via collection proxy when gameplay starts and persists over different levels
- Level collection, also spawned via collection proxy when loading a particular level, as it contains atlases for just this level, eg. snow texture vs lava textures, and we want those unloaded when we change to a different level that uses a different set of textures.
But the player (in the gameplay collection) can’t access the tilemap (in the level collection). I get an error if the player.script tries to use tilemap.get on a url that is inside the level theme’s “world”.
Alternatively, I can make the level theme the only game world when it loads:
- Level collection, which also contains a “gameplay collection” which is shared between all the different level collections for consistency. A level is spawned via collection proxy so it’s the only world, and because it contains the gameplay objects (such as the player) they can naturally interact with the tilemap because they’re all part of the same world.
But now we are loading and unloading these “global” type things that should actually just persist between levels, so we’re swapping one problem for another.
It’s not a normal trade off, because Unity has a “don’t destroy between load” or something, which keeps certain prefabs around - clunky (it should be a heirachy) but gets the job done for most cases.
Alternatively you could find ways to manage assets yourself but then you’re circumventing the features that the engine gives you which you shouldn’t do lightly.
I think for now I’ll just come up with something that keeps everything in one world and just copy out the tilemap indices into a module; the level theme collection proxy will contain a script that copies out the tilemap tile indices into a table in a module for the players to access, since it’s the only thing I need from inside the level theme proxy.
Just wondering how everyone else approaches this situation.