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
1
Question by Itsgrain42 · Sep 16, 2017 at 03:39 PM · androidnot workingsave datasave file

Save script not saving data on android device

I have found an issue with my game, due to the fact that my script (working fine on pc) doesn't work on android. I've checked to see where the data was being saved, and found out it wasn't being saved. I've looked up a tutorial for android, that didn't seem to work either. So sorry I keep posting here :/

Here's the code:

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

 public class SaveManager1 : MonoBehaviour {
 
     public GameObject CM1;
     public BuildClick1 M1;
     public GameObject CM2;
     public GoldPerSec M2;
     public float GPS;
     //public GameObject CM3;
     //public BuildClick1 M3;
 
     //public float CurrentHp;
 
     // Use this for initialization
     void Start () {
         //GPS = M2.tick;
         M1 = CM1.GetComponent<BuildClick1> ();
         M2 = CM2.GetComponent<GoldPerSec> ();
     }
 
     // Update is called once per frame
     void Update () {
 
         if(Input.GetKeyDown(KeyCode.O)){
             Save ();
             //CurrentHp = HP1.CurrentHp;
         }
 
         if(Input.GetKeyDown(KeyCode.P)){
             Load ();
         }
     }
 
     public void Save()
     {
         BinaryFormatter binaryFormatter = new BinaryFormatter();
         using (FileStream fs = new FileStream("sv1.bnxt", FileMode.Create, FileAccess.Write))
         {
             binaryFormatter.Serialize(fs, M1.gold);
             binaryFormatter.Serialize(fs, M1.goldperclick);
             binaryFormatter.Serialize(fs, M2.GPS);
         }
     }
 
     public void Load()
     {
         if (!File.Exists("sv1.bnxt"))
             return;
 
         BinaryFormatter binaryFormatter = new BinaryFormatter();
         using (FileStream fs = new FileStream("sv1.bnxt", FileMode.Open, FileAccess.Read))
         {
             M1.gold = (float)binaryFormatter.Deserialize(fs);
             M1.goldperclick = (int)binaryFormatter.Deserialize(fs);
             //float goldPerSecond = (float)binaryFormatter.Deserialize(fs);
             //M2.GetGoldPerSec (goldPerSecond);
             M2.GPS = (float)binaryFormatter.Deserialize(fs);
         }
     }
 }

Thanks for taking time to read this post, if you know what the answer to this question is, please post it! Thank you.

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 tmalhassan · Sep 16, 2017 at 04:37 PM

To save data on mobile phones, you can use playerPrefs this will work on all platforms.

Read more about it here: https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

Watch this detailed tutorial on how to implement it: https://www.youtube.com/watch?v=LBs6qOgCDOY&t=368s

or watch this one: https://www.youtube.com/watch?v=HyPeZSSKx4M

All the best :)

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 Itsgrain42 · Sep 16, 2017 at 04:45 PM 0
Share

Ah thanks, sorry that I couldn't reply right away, computer was being slow :/

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

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

Where to save player progress for playstore app? 1 Answer

Transform.position not working properly? 2 Answers

Saves on android, could not find file 0 Answers

how to save compressed image to gallery on Android ? 1 Answer

The best way to save character progress used by 2 games? 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