Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Converting PlayerPrefs to a Cloud based option

Discussion in 'Android' started by twbowen, May 29, 2015.

  1. twbowen

    twbowen

    Joined:
    Sep 27, 2013
    Posts:
    30
    Hi All,

    I have a game out on android that uses the playerprefs method of saving some data. I'd like to convert this to a cloud based option. Does anyone know of a method/plugin that I can integrate into an update that will transfer my playerprefs data to something on the cloud for android without losing the existing data that is stored in player prefs?

    Thanks in advance,
    Tom
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    Should this run on a device? e.g: when a user installs an updated version of the game, all PlayerPrefs will be synced to the cloud ?

    This is not possible AFAIK, the PlayerPrefs class doesn't have any API for enumerating all keys it currently stores.

    If you know all the different keys (and their types) that your game uses, you could probably work together an update system that will iterate all these values and upload them to a cloud-based provider.

    I am not familiar with such a provider/plugin. I know that Unity itself mentioned an "experimental" solution for this they were playing around with, but it's not out yet.

    Another option can be Parse (https://parse.com/products/core) but i've never used them myself.
     
  3. twbowen

    twbowen

    Joined:
    Sep 27, 2013
    Posts:
    30
    Thanks @liortal

    Does you know if Google Play Save saves the playerprefs?
     
  4. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,796
    Look into GameSparks, awesome cloud based solution for games. They have a NoSQL database and and events system you can use to store all player data.
     
  5. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    What I would do is create a wrapper class for your player prefs. In that wrapper have similar methods like getint and setint etc, but have them write to a dictionary stored within the wrapper class as well as updating playerprefs. Write a save and load method that saves and loads playerprefs like normal, but serializes the custom dictionary as well. You can take the byte array from the serialization and add it to whatever object you store in the cloud along with your other game save data. Honestly, it should be really simple to implement since you're just copying 2 "functions" that already exist in your game -- playerpref management, and cloud sync.
     
  6. twbowen

    twbowen

    Joined:
    Sep 27, 2013
    Posts:
    30
    @jtsmith1287 @Meltdown
    Thanks for the input guys. Does anyone know of a good walkthrough for using the Cloud save of the Google Play Games plugin on Github? I'm reading the instructions and it's just not clicking with me!
     
  7. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    You're welcome to private message me with questions. It took a decent amount of trial and error to get it working as the examples aren't 100% complete. I'm willing to help you feel things out.
     
  8. Kos-Dvornik

    Kos-Dvornik

    Joined:
    Jan 3, 2012
    Posts:
    224