If i load SaveGame immediately after saving, the data before the save will be retrieved.

I created a function that combines saving and loading in Game Instance.
This function automatically loads the SaveGame immediately after saving, and then returns the SaveGame variable (i.e. a copy of the loaded data).
However, as the content of the SaveGame increases, we found that only certain data among the loaded data would be rolled back to the state before the save.
But if i do not load the SaveGame again, the saved data will be loaded play the game next time.
So at least saving is working fine.
I am using a Sync save for saving. Because Async save cannot be use in a functions.
That might be the problem, but I need a return value.
How can I avoid this issue?

1 Like

I think you’d find that async would make things worse.

Can you show the code?

Also, why reload? Because you need the reference to make the save, so you already have the current data.

1 Like

This is it. Sorry, It’s a bit messy.

The top branch is the save, and then loaded immediately after.
The lower branch is load only.
If the SaveGame variable is empty, it will be automatically loaded.
If the data to be loaded does not exist, it will be created and saved automatically.
I thought the data needed to be saved and then loaded. is this unnecessary?

1 Like

It’s impossible to tell what’s going on there ( especially with a lot of it being off-screen ) :slight_smile:

Generally, there might be a delay before you can re-read the file, because it is actually a file. Also, like I say, when you write to the file, you already have a copy of what was written. So there’s no need to reload it.

1 Like

Yes, you are right.
When I removed reload, rollback disappeared.
And the save function still works fine.
Thank you for your advice!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.