Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by jacksongood · Nov 08, 2016 at 02:42 AM · google playsave datacloud

Google Cloud Save (Not saving)

Hey everyone,

I followed the youtube tutorial by N3K for google cloud save. I included a pop-up manager also to debug. My issue right now is, that when I press a button for "CloudSave", nothing happens. Not even a pop-up. I can successfully save and load locally.

My other script contains the necesseities for google play services. I can successfully login, look at achievemens and leaderboards.

Saving Games in Enabled in Google Dev Console.

This is my code;

 using UnityEngine;
 using GooglePlayGames;
 using GooglePlayGames.BasicApi.SavedGame;
 using GooglePlayGames.BasicApi;
 using System;
 
 public class PlayerManager : MonoBehaviour {
 
     public static PlayerManager Instance { set; get; }
     public int[] Currencies { set; get; }
     public int[] Weapons { set; get; }
 
     private bool isSaving;
     private bool hasBeenWarnedLocalSave;
 
     public bool SaveLoaded { set; get;}
     public float LastSave { set; get;}
     public float PlaytimeSinceSave { set; get;}
     public float TotalPlayTime {get { return (Time.time - LastSave) + PlaytimeSinceSave; }}
 
     // Use this for initialization
     void Awake () {
 
         PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
             .EnableSavedGames()
             .Build();
         PlayGamesPlatform.InitializeInstance(config);
 
         Instance = this;
         DontDestroyOnLoad(gameObject);
 
         // Create all my arrays
         Currencies = new int[Enum.GetNames(typeof(MoneyManager.Currency)).Length];
         Weapons = new int[Enum.GetNames(typeof(WeaponManager.Ammunition)).Length];
 
         LoadCloud();
     }
 
     void Start()
     {
         Debug.Log("Total Play Time : " + TotalPlayTime);
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     public void LoadLocal()
     {
         /*
         Currencies = new int[Enum.GetNames(typeof(MoneyManager.Currency)).Length];
 
         Currencies[(int)MoneyManager.Currency.Platinum] = PlayerPrefs.GetInt("CurrencyPlatinum");
         Currencies[(int)MoneyManager.Currency.Stardust] = PlayerPrefs.GetInt("CurrencyStardust");
 
         Weapons = new int[Enum.GetNames(typeof(WeaponManager.Ammunition)).Length];
 
         Weapons[(int)WeaponManager.Ammunition.HomingMissiles] = PlayerPrefs.GetInt("AmmunitionHomingMissiles");
         Weapons[(int)WeaponManager.Ammunition.Rockets] = PlayerPrefs.GetInt("AmmunitionRockets");
         */
         LoadFromString(PlayerPrefs.GetString("SaveString"));
     }
     public void LoadCloud()
     {
         isSaving = false;
         ((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution
         ("CTPSave", DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, SavedGameOpened);
     }
     public void SaveLocal()
     {
         /*
         // Money
         PlayerPrefs.SetInt("CurrencyPlatinum", Currencies[(int)MoneyManager.Currency.Platinum]);
         PlayerPrefs.SetInt("CurrencyStardust", Currencies[(int)MoneyManager.Currency.Stardust]);
 
         // Ammunition
         PlayerPrefs.SetInt("AmmunitionHomingMissiles", Weapons[(int)WeaponManager.Ammunition.HomingMissiles]);
         PlayerPrefs.SetInt("AmmunitionRockets", Weapons[(int)WeaponManager.Ammunition.Rockets]);
         */
         PlayerPrefs.SetString("SaveString",GetSaveString());
         PopupManager.Instance.ShowPopup("Saved", "We just saved this shit");
     }
     public void SaveCloud()
     {
         if (Social.localUser.authenticated)
         {
             isSaving = true;
             hasBeenWarnedLocalSave = false;
             ((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution
             ("CTPSave", DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, SavedGameOpened);
             PopupManager.Instance.ShowPopup("Saved", "Saved to Google Cloud");
         }
         else
         {
             if (!hasBeenWarnedLocalSave)
             {
                 PopupManager.Instance.ShowPopup("Save Cloud Error", "Not Connected");
                 hasBeenWarnedLocalSave = true;
                 SaveLocal();
             }
         }
         PopupManager.Instance.ShowPopup("Button Pressed", "Nothing happened.");
     }
     public void SavedGameOpened(SavedGameRequestStatus status, ISavedGameMetadata game)
     {
         if (status == SavedGameRequestStatus.Success)
         {
             if(isSaving) // Writing Data
             {
                 byte[] data = System.Text.Encoding.ASCII.GetBytes(GetSaveString());
                 TimeSpan playedTime = TimeSpan.FromSeconds(TotalPlayTime);
                 SavedGameMetadataUpdate.Builder builder = new SavedGameMetadataUpdate.Builder();
 
                 SavedGameMetadataUpdate update = builder.Build();
                 ((PlayGamesPlatform)Social.Active).SavedGame.CommitUpdate(game, update, data, SavedGameWritten);
             }
             else // Reading Data
             {
                 ((PlayGamesPlatform)Social.Active).SavedGame.ReadBinaryData(game, SavedGameLoaded);
             }
         }
         else
         {
             PopupManager.Instance.ShowPopup("Save State", "Error" + status);
         }
     }
     public void SavedGameLoaded(SavedGameRequestStatus status, byte[] data)
     {
         if(status == SavedGameRequestStatus.Success)
         {
             LoadFromString(System.Text.ASCIIEncoding.ASCII.GetString(data));
         }
         else
         {
             Debug.Log("Error reading game:" + status);
             PopupManager.Instance.ShowPopup("Error", "Error reading game :" + status);
         }
     }
     public void SavedGameWritten(SavedGameRequestStatus status, ISavedGameMetadata game)
     {
         if (status == SavedGameRequestStatus.Success)
         {
             // handle reading or writing of saved game.
         }
         else
         {
             // handle error
         }
     }
     private void LoadFromString (string savedData)
     {
         if (savedData == "")
             return;
 
         string[] data = savedData.Split('|');
 
         // Time
         string[] misc = data[0].Split('%');
         PlaytimeSinceSave = float.Parse(misc[0]);
         
         // Currency
         string[] currency = data[1].Split('%');
         Currencies[(int)MoneyManager.Currency.Platinum] = int.Parse(currency[0]);
         Currencies[(int)MoneyManager.Currency.Stardust] = int.Parse(currency[1]);
 
         // Ammunition
         string[] ammo = data[2].Split('%');
         Weapons[(int)WeaponManager.Ammunition.HomingMissiles] = int.Parse(ammo[0]);
         Weapons[(int)WeaponManager.Ammunition.Rockets] = int.Parse(ammo[1]);
 
         SaveLoaded = true;
     }
     private string GetSaveString()
     {
         string saveData = "";
 
         // Time
         saveData += TotalPlayTime.ToString() + '|';
         LastSave = Time.time;
 
         // Money
         saveData +=
             Currencies[(int)MoneyManager.Currency.Platinum].ToString() + '%' +
             Currencies[(int)MoneyManager.Currency.Stardust].ToString() + '|';
 
         // Ammunition
         saveData +=
             Weapons[(int)WeaponManager.Ammunition.HomingMissiles].ToString() + '%' +
             Weapons[(int)WeaponManager.Ammunition.Rockets].ToString() + '|';
 
         return saveData;
     }
 
     private void OnApplicationQuit()
     {
         Debug.Log("Yo we just saved this shit");
     }
 }
 
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jacksongood · Nov 08, 2016 at 03:00 AM 0
Share

I moved around some code to ensure that I have proper order.

Now I know that my "save button" is working, but the important code doesn't run.

     public void SaveCloud()
     {
         if (Social.localUser.authenticated)
         {
             isSaving = true;
             hasBeenWarnedLocalSave = false;
             ((PlayGamesPlatform)Social.Active).SavedGame.OpenWithAutomaticConflictResolution
             ("CTPSave", DataSource.ReadCacheOrNetwork, ConflictResolutionStrategy.UseLongestPlaytime, SavedGameOpened);
             Popup$$anonymous$$anager.Instance.ShowPopup("Saved", "Saved to Google Cloud");
         }
         else
         {
             if (!hasBeenWarnedLocalSave)
             {
                 Popup$$anonymous$$anager.Instance.ShowPopup("Save Cloud Error", "Not Connected");
                 hasBeenWarnedLocalSave = true;
                 SaveLocal();
             }
         }
         Popup$$anonymous$$anager.Instance.ShowPopup("Button Pressed", "Nothing happened.");
     }

I just get the "Button Pressed, Nothing Happened" message.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AEssid · Aug 03, 2017 at 11:19 PM

me too same problem .. Have you found a solution to this problem?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Akki-bhatt · Aug 05, 2017 at 07:28 AM 0
Share

Hello, you can use this asset.Hope your problem solved. https://www.assetstore.unity3d.com/en/#!/content/95371

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

78 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to import data from serialized file to google play service cloud save? 0 Answers

The best overloaded method match for google play games 1 Answer

Problem With Unity Cloud Save (Google Play Services) 0 Answers

Android game freezes after Timed out connecting to Google Play 0 Answers

I can't get Google cloud saving working 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges