Hello. I created a custom iSaveFileHandler for Xbox, and I think everything is working except for Loading. Xbox's Load method takes some time, so when I run an ActionList with Load, it seems that there is not enough time for Xbox's Load to complete and thus the Load string is returned as null. I'm using AC version 1.74.2 and Unity 2022.3.39f1. Is there an easy way to correctly implement the loading without updating AC? I've written some overrides and updating it might be very complicated. This is the snippet of my iSaveHandler. I redacted some lines, but the main idea is there.
public string Load(SaveFile saveFile, bool doLog)
{
string loadedData = null;
string containerName = saveFile.fileName;
XboxServices.savesManager.GetOrCreateContainer(containerName, =>
{
if (succeeded)
{
XboxServices.savesManager.LoadGame((blobs) =>
{
if (failed)
{
Debug.LogError("Error when loading GameSave.");
return;
}
if (succeeded && blobs.Length > 0)
{
Debug.Log("loading data succeeded");
loadedData = System.Text.Encoding.ASCII.GetString(blobs[0].Data);
}
});
}
});
Debug.Log($"loadedData: {loadedData}");
return loadedData;
}
So loadedData is returned as empty before it gets its value from loadedData = System.Text.Encoding.ASCII.GetString(blobs[0].Data);
. Any help is appreciated.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
What's the output to the Console in this situation?
I wouldn't have expected the function to just continue on if the LoadGame function was taking too long, but AC now relies on a callback system to allow such operations to take as long as necessary. This was introduced in v1.76.1.
I'd recommend trying out the latest release in a fresh project and see if the change causes the loading process to then work correctly. We can see about what's necessary for a potential upgrade later.
The output of my Debug.Log is "loadedData: ". And it appears before "loading data succeeded". I tried creating another string to debug the loaded data and it seems that it is loading correctly. Its values just doesn't get returned to loadedData.
I'll try the new version of AC and let you know.
Hi. So I downloaded the newest AC version to a new project and looked through the scripts.
Like I said before, updating AC to the newest version will surely break my entire game, so I did the following:
In the end, my new Load method looks like this:
I also made sure to update the Delete and Save methods of my SaveFileHandler to include the callbacks (I took a look at the other SaveFileHandlers to see how it's done)
Does this sound correct? Are there any other scripts I should modify? I can provide more details if you would like to know how exactly I edited the scripts. So far, my tests have worked correctly.
I couldn't give a definitive answer, as it would depend on the exact changes you made to v1.74.2. Rather than copying individual methods from SaveSystem, however, I'd say it would be safer to import the one from the latest release completely, and fix any issues you then get.
The callback implementation is correct, however.
I tried replacing the entire script and fixing the errors. But so many errors came up that I feel like I'm breaking more than I'm fixing. I will send you the script in a private message, if you would like to take a look at the changes I made.
Too much has changed between versions. Looks like the best approach - if updating fully is not possible - is to go back to your earlier attempt, and test thoroughly.