Is there a way to not call OnApplicationFocus when the game exit?
I notice that my save system will break if I try to save when the application exits, so I would like to only save when the application loses focus, but it turns out OnApplicationFocus will be called when the game exit.
So is there a way to ignore it or know the game is exiting when it loses focus?
Implement OnApplicationQuit and set a bool so you know that this time losing focus you shouldn‘t save. But I‘m not sure which of the two get called first.
In any case, saving when losing focus is a tad weird. A text editor might do it since the text (code) file may be needed to be up to date in another app. But a game really shouldn‘t do this but rather save on demand or in fixed intervals (timed or when completing a task/level).
my game is a roguelite game, I don’t want the player to be able to run away from the situation by quitting and reloading the previous save.
if he wants to exit, he can use the exit button inside the game, which will automatically save the game.
But he can also quit the game outside the game by clicking the X button in the window, but I would like to also save the game, so when he tries to click that button, at first he would need to lose focus, which should cause the game to save.
oh, never mind, the save system didn’t break, the load system works in editor but breaks in built game
well in that case why not simply save in „wantstoquit“?
If player just tabs out, the game would pause (unless you set the player to keep running in background). When tabbed out and the player quits, you get the quit messages anyway. Though some players will quickly find out that one can force-kill the app in some way and may even bind that to a hotkey. There‘s no foolproof system to prevent this kind of cheating.
never mind, it turns out to be a misunderstanding
thanks anyway