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 /
avatar image
0
Question by JackMac290400 · Jun 29, 2016 at 10:53 PM · savesave datasaveloaduninstallreinstall

Android, How can I permanently save data? (A couple variables)

Hi, I have made a game which the user can get a score from and their high score is kept in playerPrefs, I also use playerPrefs to record if the user has purchased "no ads" which I assumed would always save the data but earlier I discovered that if the user uninstalls the application and re-installs it then the playerPrefs are lost.

How can I save this data even when the application has been uninstalled?

Comment
Add comment · Show 7
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 bodec · Jun 30, 2016 at 01:26 AM 0
Share

Not 100% but this may be a spot to check Bianary

avatar image CodeElemental · Jun 30, 2016 at 07:44 AM 1
Share

I would not recommend that. I mean, from a user perspective I would not like apps to leave their data after i uninstall them.

The proper way to do that is store the relevant data to a server, and upon starting the application if no local data is present, retrieve it from the server.

avatar image JackMac290400 CodeElemental · Jun 30, 2016 at 07:58 AM 0
Share

Thanks for replying, if I was gonna go down the server route then how would I go about this?

avatar image CodeElemental JackMac290400 · Jun 30, 2016 at 08:19 AM 1
Share

Well, for the local storage, playerprefs works just fine. I would add encryption since the data is susceptible to editing. As for the remote option, you're practically free to go any way you want. You would need some sort of DB+Authentication to store data for multiple users.

For the 'first-run' logic i would suggest checking for local data to be the condition. If no local data is found (key in the playerprefs) then it's your first run and check with the server to get it.

Show more comments
Show more comments

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by sindrijo · Jun 30, 2016 at 05:19 PM

You can save arbitrary strings that is tied to a users google play game services identity, so that it will be persistent for the user even if the user switches devices. The tricky part is how to sync the data between them. CloudOnce is a totally free asset with that makes this a breeze.

Check out the getting started page: http://trollpants.github.io/CloudOnce/gettingStarted.html

You may notice that it also supports iOS and helps with things like achievements and leaderboards as well.

https://www.assetstore.unity3d.com/en/#!/content/35621

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 ZyntharNOR · Dec 31, 2016 at 04:21 AM 0
Share

New URL: http://github.com/jizc/CloudOnce

avatar image
0

Answer by DroidifyDevs · Jun 30, 2016 at 01:44 PM

You'd probably have to post the data to a server.

However you could try serialization... but I'm not sure if that will save after an uninstall.

This is what I use to serialize a dictionary, feel free to try it out:

 using UnityEngine;
 using System.Collections;
 using System.IO;
 using System.Runtime.Serialization.Formatters.Binary;
 using System.Runtime.Serialization;
 using System;
 using System.Collections.Generic;
 
 //this is SaveInfoNewer.cs
 //this script saves and loads all the info we want
 public class SaveInfoNewer : MonoBehaviour
 {
     public SlotLoader SlotLoader;
     //data is what is finally saved
     public Dictionary<string, int> data;
 
     void Awake()
     {
         //LoadUpgradeData();
         LoadData();
         //WARNING! data.Clear() deletes EVERYTHING
         //data.Clear();
         //SaveData();
     }
 
     public void LoadData()
     { 
         //this loads the data
         data = SaveInfoNewer.DeserializeData<Dictionary<string, int>>("PleaseWork.save");
     }
 
     public void SaveData()
     {
         //this saves the data
         SaveInfoNewer.SerializeData(data, "PleaseWork.save");
     }
     public static void SerializeData<T>(T data, string path)
     {
         //this is just magic to save data. 
         //if you're interested read up on serialization
         FileStream fs = new FileStream(path, FileMode.OpenOrCreate);
         BinaryFormatter formatter = new BinaryFormatter();
         try
         {
             formatter.Serialize(fs, data);
             Debug.Log("Data written to " + path + " @ " + DateTime.Now.ToShortTimeString());
         }
         catch (SerializationException e)
         {
             Debug.LogError(e.Message);
         }
         finally
         {
             fs.Close();
         }
     }
 
     public static T DeserializeData<T>(string path)
     {
         //this is the magic that deserializes the data so we can load it
         T data = default(T);
 
         if (File.Exists(path))
         {
             FileStream fs = new FileStream(path, FileMode.Open);
             try
             {
                 BinaryFormatter formatter = new BinaryFormatter();
                 data = (T)formatter.Deserialize(fs);
                 Debug.Log("Data read from " + path);
             }
             catch (SerializationException e)
             {
                 Debug.LogError(e.Message);
             }
             finally
             {
                 fs.Close();
             }
         }
         return data;
     }
 }


In theory this should save the data even after uninstalling, but only way to find out is to try it out.

Comment
Add comment · 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
0

Answer by EDevJogos · Jun 30, 2016 at 02:09 PM

I would suggest using a database for this, you can use kii it's free and has native support for unity, quite simple to implement too, just follow the getting started tutorial:

https://docs.kii.com/en/guides/unity/

This page has some sample cods, as you can see it's really simple:

https://docs.kii.com/en/samples/Gamecloud-Unity/

Comment
Add comment · 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
0

Answer by rmassanet · Jul 13, 2016 at 12:09 PM

You could use Firebase from Google. They have a Unity plugin for it:

https://github.com/firebase/Firebase-Unity

That way you can store data in their cloud, associated to the user's Google Play Game's account.

Good luck!

Comment
Add comment · 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

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

51 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

Related Questions

Error while saving game: SerializationException: Type 'UnityEngine.GameObject' in Assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable. 0 Answers

Saving Melee Combat Template Pack (MY LAST PROBLEM) 1 Answer

Tell me how to open these files on android 0 Answers

Save Game Sceenes user quit aplication, Can I save the scene as a whole while leaving the game? 0 Answers

I followed the Brackeys save tutorial and it won't work 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