Quick question on game state as I come from a android background and I know their are certain lifecycles in a app when you need to use certain constructs like ViewModels to keep data in memory when the app is placed in the background for a minute, or screen rotations occur so it doesn’t just up and disappear & my question here’s, does defold have anything like this or is this and if not why ?
To note I’m aware we have sys.save() for disk writes, and have inkling that defold kinda handles some of this implicitly but because I’m not 100% based on the docs I wanted to ask veterans here.
Defold has no built in mechanism for serializing game state. As long as the Android OS keeps the game in memory the game will keep running when you switch back to it. If the OS kills the process the game will do a cold start and start from scratch. You will need to manage and persist game state yourself if you want to guarantee that the player should be able to return to the same state. Like you said, sys.save() could be used for this. Depending on your game you might want to save at the end of each level, or at a regular interval. There is also a window.set_listener() where you can get a FOCUS_LOST event but I am not sure if you get this event at the right time on Android.
Grand thanks very much for the info alright so no save instance state or view model constructs exist, just in case by case best to use sys save to cover against os killing the app mid level progression, is it also true that defold tries best not to kill activity losing the game data when config changes like orientation, change size, placed in background change happen etc. I observe this behaviour to be true in my testing but kinda just wanted to check if its like a thing to rely or should also cover those cases in my code.