Hello. I wanted to load game related collection only when game starts not when I’m loading the main menu. So it was done, but with more and more animations the loading of these collections becomes more visible. Current load/unload structure is like this:
Main menu → loads Game
Game → can show (and load) various pop-up collections which can also be hidden after use
Game → loads Main Menu when we are getting back from the game.
Idea is to have all pop-up screen preloaded during the load of the Game from Main Menu. And unload them (if they weren’t shown) during the Menu load. I can use monarch.preload. And it will preload it, but only ones. If I hide this screen (and this is natural behavior) it will require preloading again.
If the collection is preloaded from the beginning (via boolean in collection proxy setting) it will always be preloaded. But in this case, I will need to manually clean guis in that collection (which I really do not want to do ), as it will retain all information from the last game.
So is there a way to ‘clear’ always preloaded collections or somehow preload collections for some period with options to unload it manually? I am also open to other suggestions)
P.S. All pop-up collections mentioned above basically consists of one or two guis elements. They were put into separate collections to not to bother with their cleanup after each call.
I do. But it’s preloading it only once. So if in the loading of the game I preload all popups, I can use them only once. After monarch.hide() it will be unloaded for the next monarch.show().
Ah, I understand. What if we add an option to keep the popup preloaded somehow? It could be an option to monarch.hide():
-- hide screen but do not unload resources
monarch.hide("some_screen", { keep_loaded = true }, cb)
The same could be done for monarch.back()
-- go back but do not unload resources for current screen
monarch.back({ keep_loaded = true }, cb)
Or it could be an option to monarch.preload():
-- preload and keep screen loaded even after navigation using hide() or back() (but not after unload())
monarch.preload("some_screen", { keep_loaded = true }, cb)
I’ve added a keep_loaded option to monarch.preload() and released a new version. The new option will ensure that a preloaded screen. doesn’t get unloaded due to a navigation event.
I’m getting such error when I’m trying to use monarch.unload()
ERROR:GAMESYS: The collection /Tasks/Tasks.collectionc could not be disabled since it is not enabled. Message 'disable' sent from Main:/4.Tasks#screen_proxy to Main:/4.Tasks#Screen.
@russelkgd I’ve reopened the ticket. Could you please provide a clear step by step guide to verify this behavior. I think I know what to test, but I’m not 100% sure and want to avoid guessing.
If you click on button “No preload show”. It will use regular monarch.show to load level without preloading popup screen.
If you click on button in the middle it will open popup screen.
If you click outside the window it will be hidden by monarch.hide, which will result in unloading the screen and final(self) been executed.
If you click on left button it will return to main menu. This is expected behavior.
If you click on button “Preload show”. It will use preload of popup screen and then regular monarch.show to load level.
If you click on button in the middle it will open popup screen.
If you click outside the window it will be hidden by monarch.hide, but without unloading it. final(self) won’t be triggered. Which is also expected behavior.
If you click on left button it will return to main menu. It will use monarch.unload - to unload popup screen and then regular monarch.show to load main menu. During the process it should unload the pop up and call final(self) there, which is not happening. That’s unexpected behavior. Basically the screen is not unloading.
Ah, I see. Ok, what I did was to make the explicitly preloaded screen act exactly like a screen where the Preload checkbox is ticked. And in such a case any call to monarch.preload() will be ignored. This is in my opinion a bit strange. Calling monarch.unload() should unload a preloaded screen, regardless if it was preloaded via monarch.preload() or on creation using the checkbox. I’ve released a new version which fixes this: Release Monarch 3.7.0 · britzl/monarch · GitHub