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 Necrohunter · May 20, 2018 at 05:22 PM · mobilesavingonline

saven data files (Units, Gold, Items, unlocked levels) on devices

hey there i am developing a mobile game and reached the point where i have to figure out how to save the data of the players. like, how much golg, what units and so on... i heard, playerprefs are not good, because they dont encrypt or something..? so i would like to know what is a good solution, what are other studios using? i would love to hear some different possibilities and why they are good :)

oh yeah, it will be an offline game, but maybe i want to make later a highscore or add an multiplayer..

thank you much !

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MT369MT · May 20, 2018 at 06:17 PM

Hi, I use custom binary files for saves. If you search "Saving Data in Unity" on youtube you will find many saving options like PlayerPrefs, Custom Binary Files, XML Files, Scriptable Objects and in each there are explained the pros and cons. Ask if you need something more.

Comment
Add comment · Show 5 · 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 Necrohunter · May 20, 2018 at 08:22 PM 0
Share

"custom binary files" sound complicated for me :p but i will check out youtube for it.

are custom binary files fine for an offline game on mobile? or is this way to much and there are other options? what would you use?

avatar image MT369MT Necrohunter · May 20, 2018 at 09:21 PM 0
Share

This is the complete script of the Custom Binary File (I modified it a bit). Add it to an empty gameobject called "SaveControl" and then add also the second script in the scene. If you change the CurrentLevel value (in play mode use up and down arrow to modify it) and then you exit play mode and restart it, you will see that the int will remain the previous value.

SaveControl script:

using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Runtime.Serialization.Formatters.Binary; using System.IO;

public class SaveControl : $$anonymous$$onoBehaviour {

 public static SaveControl Control;

 public bool CanLoad;
 public bool Loaded;
 public float LoadCounter;

 void Awake()
 {
     if (Control == null)
     {
         DontDestroyOnLoad(gameObject);
         Control = this;
     }
     else if (Control != this)
     {
         Destroy(gameObject);
     }
 }

 void Start()
 {
     CanLoad = true;
     Loaded = false;
 }

 void Update()
 {
     if (CanLoad == true)
     {
         LoadCounter += Time.deltaTime;

         if (LoadCounter >= 0.1)
         {
             Load();
             LoadCounter = 0;
             CanLoad = false;
         }
     }
 }

 private void OnApplicationQuit()
 {
     if (Loaded == true)
     {
         Save();
     }
 }

 public void Save()
 {
     BinaryFormatter BF = new BinaryFormatter();
     FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat");

     PlayerData Data = new PlayerData();


     //I save my CurrentLevel int, in my data file
     Data.CurrentLevel = Level.CurrentLevel;


     BF.Serialize(file, Data);
     file.Close();
 }

 public void Load()
 {
     if (File.Exists(Application.persistentDataPath + "/playerInfo.dat"))
     {
         BinaryFormatter BF = new BinaryFormatter();
         FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", File$$anonymous$$ode.Open);
         PlayerData Data = (PlayerData)BF.Deserialize(file);
         file.Close();
         

         //I load in my CurrentLevel int, my data that I previous stored
         Level.CurrentLevel = Data.CurrentLevel;


         Loaded = true;
     }
 }

}

[Serializable] class PlayerData {

 public int CurrentLevel;

}

Level script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Level : $$anonymous$$onoBehaviour {

 public static int CurrentLevel;

 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {

     if (Input.Get$$anonymous$$eyDown("up"))
     {
         CurrentLevel += 1;
     }
     if (Input.Get$$anonymous$$eyDown("down"))
     {
         CurrentLevel -= 1;
     }

     Debug.Log(CurrentLevel);

 }

}

avatar image Necrohunter MT369MT · May 20, 2018 at 09:41 PM 0
Share

allright, this is quit interessting. do it saves more than 1 mb? (like playerprefs) or can you save as much data as you want?

Show more comments
avatar image Necrohunter · May 20, 2018 at 08:27 PM 0
Share

oh and btw, the tutorials are very good u told me to watch, thanks for that.

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

119 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 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

Saving game respectively my level, when I restart my game. 0 Answers

Cross Platform Saving 1 Answer

Serializing GameObject Data with XML, Adaptation 2 Answers

Cannot run database when convert to exe or play in android devices? 2 Answers

Android and PlayerPrefs.Save 2 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