The collection could not be unloaded since it was never loaded (SOLVED)

I am developing a game that have 4 collections: menu, credit, game and game over collection. I follow the tutorial but it have only 2 scenes that call each other. In my case, I have 3 scenes
In the menu scene I have 2 options in the gui start and credit. In the game over scene I have restart and menu option. When I click credit in menu, it will load the credit scene but when I click back to menu I see this error

ERROR:GAMESYS: The collection /scenes/game_over/game_over.collectionc could not be unloaded since it was never loaded. Message ‘unload’ sent from controller:/loader_controller#controller to controller:/loader_controller#game_over_proxy.

I see the same error when I click menu in game over scene

ERROR:GAMESYS: The collection /scenes/credit/credit.collectionc could not be unloaded since it was never loaded. Message ‘unload’ sent from controller:/loader_controller#controller to controller:/loader_controller#credit_proxy.

This is my code

if message_id == hash(“show_menu”) then
msg.post("#menu_proxy", “load”)
msg.post("#game_over_proxy", “unload”)
msg.post("#credit_proxy", “unload”)
end

msg.post("#game_over_proxy", “unload”)
msg.post("#credit_proxy", “unload”)

These two lines will be throwing an error if you haven’t loaded these collections using the “load” message.

I suggest you keep some state variable to keep track of what collections you have actually loaded.

When I receive the proxy_loaded message, I can save the sender to a local variable and call it to unload when I load the new collection, right?

Yes, exactly, but remember that that “local” must be in the scope where you are trying to use it ofc.

Here’s another example of loading and unloading screens with a controller script that tracks the state:

@britzl I follow your example but my collection refer to 2 other collections and it causes the error above.

Yes, but as Matthias points out, you unload two collections, credits and game. Are both loaded? If not, then unload just the one that is loaded.

1 Like

@britzl Both credit and game over collection refer to menu collection. If I am back to menu from credit, it will unload credit but game over has not been loaded yet. Vice versa for game over collection. And @Mathias_Westerdahl solution worked well. Thank you guys

1 Like

Quick question. Is it a serious problem to try to unload a collection which is already unloaded? Imagine There’s a lazy developer who does something like this

		msg.post("#levelselect", "unload")
		msg.post("#levelselect", "load")

Just to make sure that the level select screen is always unloaded. An error is thrown to the console, but what implications are there?

None. You’re wasting some CPU cycles but that’s it.