playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.46k stars 965 forks source link

Google play save loading - SaveGameRequestStatus returns Bad Input #3029

Closed OWL7seven closed 3 years ago

OWL7seven commented 3 years ago

Hi,

So for the past few weeks, I've been having issues with a few things, some have been resolved, but note everything was working at one point, and i haven't touched any of the code that handles my saves.

Currently i have an issue loading my save data from the google play select save UI. its saving correctly and i able to see all instance of the save files, i was able to load successfully until recently.

the issue i get in my logs on the device is the SaveGameRequestStatus returns BadInputError, as seen on the by the last section of the code below, i m not sure why this is happening. any help would be much appreciated.

before this log, i am getting these following warnings (this could be from writing the save files):

public static void ShowSelectSaveUI()

    `{
        if (PlayGamesPlatform.Instance.localUser.authenticated)
        {
            uint maxNumToDisplay = 5;
            bool allowCreateNew = false;
            bool allowDelete = true;

            ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
            savedGameClient.ShowSelectSavedGameUI("Select saved game",
                maxNumToDisplay,
                allowCreateNew,
                allowDelete,
                OnSavedGameSelected);
        }
    }

    public static void OnSavedGameSelected(SelectUIStatus status, ISavedGameMetadata game)
    {
        if (status == SelectUIStatus.SavedGameSelected)
        {
            Debug.Log($"online save selected success - is open: {game.IsOpen}");
            PlayGamesPlatform.Instance.SavedGame.ReadBinaryData(game, ParseSaveData);
        }
        else
        {
            Debug.Log("online save selection failed");
            // handle cancel or error
        }
    }
    private static void ParseSaveData(SavedGameRequestStatus status, byte[] data)
    {
        if (status == SavedGameRequestStatus.Success)
        {
            string stringData = Convert.ToBase64String(data);
            Data saveData = SaveSystem.ConvertSaveDataFromString<Data>(stringData);
            SaveSystem.SaveData(saveData);
            SceneManager.LoadScene(0);
            Debug.Log("online save - saved");
        }
        else
        {
            Debug.LogError($"Game save ParseSaveData failed: {status}");
        }
    }`

Here is the Code i use to write my save files, its been working so far, as i can see the files in the google UI

private static void WriteSavedGame(ISavedGameMetadata game, string stringData, bool withScreenshot) {

        Data saveFile = SaveSystem.ConvertSaveDataFromString<Data>(stringData);
        byte[] savedData = Convert.FromBase64String(stringData);
        OpenSavedGame(saveFile.saveID);
        Debug.Log($"Writing Save game- {saveFile.saveID}");
        SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder()
            .WithUpdatedPlayedTime(TimeSpan.FromSeconds(saveFile.totalSeconds))
            .WithUpdatedDescription("Saved at: " + System.DateTime.Now);

        if (withScreenshot)
        {
            byte[] pngData = screenshot.EncodeToPNG();
            builder = builder.WithUpdatedPngCoverImage(pngData);
        }

        SavedGameMetadataUpdate updatedMetadata = builder.Build();
        ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame;
        if (game != null)
        {
            PlayGamesPlatform.Instance.SavedGame.ReadBinaryData(game, ParseSaveDataLoad);`
OWL7seven commented 3 years ago

OK after 3 weeks of trying to find a solution, its seem that you need to "open" the save file when saving and loading.

so this means using :

private static void WriteOpenSavedGame(string filename) { ISavedGameClient savedGameClient = PlayGamesPlatform.Instance.SavedGame; savedGameClient.OpenWithAutomaticConflictResolution(filename, DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLastKnownGood, WriteOnSavedGameOpened); }

and there after you can use PlayGamesPlatform.Instance.SavedGame.ReadBinaryData to load that save file to get the byte data.

userqt commented 2 years ago

I am also getting this error now, I am opening the file before save exactly as it is mentioned above. Could it be some other reason for that @OWL7seven?

jzapdot commented 2 years ago

Nearly two years later this issue is still present (occurs currently in latest release 0.11.01. When can we expect this to be resolved?