I already made a topic about that, but a new problem arises…
I am make a game that counts the time when the app on the phone is on background. Everything works well and the time passed is calculated when the player comeback. My problem was that when i close the app without focus, the game wasn’t saving the datetime value on json file, but a kind user helped me with that.
The problem is that, when i reopen the game and call the same function that calculates the time passed without focus, the function doesn’t work, even with the old datetime stored.
I tried to use (int)timespan.total seconds to store as int in a variable on my json file, but still without sucess, i tried calculate the old datetime - datetime.now, and nothing works. I am getting very depressed with this problem. It’s like finish the app without focus breaks everything.
Maybe gamedev it’s not for me…
That just sounds like you wrote a bug… and that means… time to start debugging!
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...);
statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.
Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.
You can debug on device but you can also output data to UI text fields on the device screen, which for app launch issues like this one might be a lot easier to get information about what is happening, or at least use it as an adjunct source of crosschecking your program’s operation.
Well. I don’t know why, but debbuging with text on my phone, i can see that the last datetime it’s stored, but the function that calculates how many seconds passed only works when i pause the application and after that comeback to application.
When i use the exact same calculation, on awake or start without any if checks, the game calculation about time passed don’t work. This is so strange
I fixed this cursed game.
The problem was: i was trying to save the values when game was closed on background and onapplicationquit was never called, because it’s different on mobile. So, instead of save the game only when the game was closed(like on pc version), i save the game all the times where the player put the app on background(with onapplicationpause function).
Now i have the exact time of the app on background before is closed.
Thanks Kurt, after some debugging i discover the problem.
1 Like