#Save System fails to save data sometimes.

1 messages · Page 1 of 1 (latest)

calm parrot
#

I’m working on a game which has a saving system. Every time the player exits the game, the system saves and this is suppose to work every time.

However while this works, it’s inconsistent at least in the Unity Editor so far (Have not checked how it is on exe files). Whenever I stop playing, my save function would sometimes fails to overwrite the json I have, which is currently stored in my resources folder.

I don’t get any errors related to quitting the application, except for the occasional object not found from the Save Data. Any advice?

Here is my code.

gentle hearth
#

Which line is 61?

#

Also note that this won't work in a build anyway. The assets directory doesn't exist in the build. You should use persistentDataPath instead

calm parrot
#

Yeah, that makes sense.

gentle hearth
#

Does that still throw the same error on the same line? You've changed the code

calm parrot
#

I realized what the issue was when you brought up the line and realized that the OnApplicationQuit was calling the saveData without checking if that the gamedata is not null

#

There shouldn't be an error relating to object reference, however the same problem still exists with the fact that the save system doesn't save the data sometimes.

#

Here

#

There's no issue with the loading, it's the saving which appears to be the issue.

gentle hearth
#

First change the save system to not use Resources because you won't be able use that anyway, then see if the problem continues. It's possible that resources aren't available during the shutdown process

calm parrot
#

thats true

gentle hearth
#

Then check if it happens even if you save during the play, not only in OnApplicationQuit

calm parrot
#

I'll change the path and let you know

calm parrot
#

Okay! Update, I changed the path and it saves consistently now!