playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.43k stars 953 forks source link

ShowSelectSavedGameUI returns null saved game, cannot create new saves #3195

Closed maziluradu closed 1 year ago

maziluradu commented 1 year ago

Describe the bug I am using PlayGamesPlatform.Instance.SavedGame.ShowSelectSavedGameUI() in order to create a new game save for the player. The app compiles just fine, the authentication works. The player can see the menu for selecting an existing saved game or create a new one, but as soon as the "+" icon is pressed nothing happens on the device, the menu gets closed and that's all. After the menu gets closed, the callback returns a "SavedGameSelected" status with a null savedgame.

To Reproduce Steps to reproduce the behavior:

  1. Use Play Games Plugin for Unity, ver. 11.0.1
  2. Use PlayGamesPlatform.Instance.SavedGame.ShowSelectSavedGameUI() after authenticating in order to make the player create a new save
  3. Player hits the "+" button inside the saved games prompt
  4. Menu closes, callback from ShowSelectSavedGameUI() returns "SavedGameSelected" status and null ISavedGameMetadata

Expected behavior ShowSelectSavedGameUI() should return a valid game save instead of null.

Observed behavior ShowSelectSavedGameUI() returns a null ISavedGameMetadata

Bug Report https://drive.google.com/file/d/1bP0lzPFdTR5va6uYLZC1sQAeQeDjvfiJ/view?usp=sharing

Versions

smile616 commented 1 year ago

@maziluradu thank you for the detailed report.

That is WAI. In other words "SavedGameSelected" status and null ISavedGameMetadata means that user tapped "+" button (create new). "SavedGameSelected" status and non null ISavedGameMetadata means that user selected existing saved game. Sorry that the documentation doesn't state this explicitly.

Reasoning:

  1. SavedGameMetadata is always created by the game and have to be provided to save the game state.
  2. When user select "create new" saved game, there is no saved game yet and SavedGameMetadata hasn't been created yet.
maziluradu commented 1 year ago

@smile616 Could you please provide an example of how we can create a saved game with the most recent plugin version? I have tried creating a class which implements the ISavedGameMetadata interface, however I get an error in the console stating that the saved game was not created by the current client.

smile616 commented 1 year ago

@maziluradu Please take a look at the README.md:

  1. you need to open a saved game using savedGameClient.OpenWithAutomaticConflictResolution or savedGameClient.OpenWithManualConflictResolution. See: https://github.com/playgameservices/play-games-plugin-for-unity/blob/master/README.md#opening-a-saved-game This will create a new saved game if it didn't exist.

  2. you need to write the game state. See https://github.com/playgameservices/play-games-plugin-for-unity/blob/master/README.md#writing-a-saved-game

maziluradu commented 1 year ago

@smile616 Thank you very much for the explanation. It felt a bit confusing at first, thought creating a new save would create an ISavedGameMetadata with a blank state.

I finally got it to work; however, when using CommitUpdate, it always closes the saved game, and I need to reopen it right after. Is this the intended behavior? I would also like to save the game when some critical change is being done, not only when the application closes.

smile616 commented 1 year ago

@smile616 Yes, it's intentional to close the saved game with CommitUpdate.

Ideally game should open the saved game right before it intends to update the saved state and call CommitUpdate right after the update. Your example "when some critical change is being done" fit that case. Other common case would be update saved state on user's demand.

Please note: if game is closed before it had a chance to call the CommitUpdate, the saved state will be lost.