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 surfuay · Dec 06, 2018 at 05:29 AM · saveloadloadingsaving

Save works for computer but not once i create the build and load it on the android

Not sure what's happening but when I test the game in the editor it works great. Calls the saved score and everything. Once i create the build and put it on my android it the save and load functions no longer work. Here's the code.

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

public class Start_Screen_UIManager : MonoBehaviour {

 public static Start_Screen_UIManager ssUIManager;



 public Text savedHighScoreText;
 public int savedHighScore = 0;
 

 private void Awake()
 {
  
     if (ssUIManager == null)
     {
         
         ssUIManager = this;
     }

     else if (ssUIManager != this)
     {
         Destroy(gameObject);
     }
     
 }


 private void Start()
 {
     Load();
 }


 public void Update()
 {
     if (savedHighScore < ScoreManager.scoreManager.newHighScore)
     {
         savedHighScore = ScoreManager.scoreManager.newHighScore;
         savedHighScoreText.text = "High Score: " + savedHighScore;
     }
     else
     {
         savedHighScoreText.text = "High Score: " + savedHighScore;
     }


 }

 public void OnDisable()
 {
     Save();
 }

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

     ScoreData data = new ScoreData();
     data.score = savedHighScore;
     

     bf.Serialize(file, data);
     file.Close();
 }

 public void Load()
 {
     if (File.Exists(Application.persistentDataPath + "/score.dat"))
     {
         BinaryFormatter bf = new BinaryFormatter();
         FileStream file = File.Open(Application.persistentDataPath + "/score.dat", FileMode.Open);
         ScoreData data = (ScoreData)bf.Deserialize(file);
         file.Close();

         savedHighScore = data.score;
         
         
     }
 }

} [Serializable] class ScoreData { public int score;

}

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
1

Answer by Vega4Life · Dec 06, 2018 at 08:27 PM

I have made some builds for android, and to write, you need to change the permissions to the SD Card.

In your player settings -> other settings, there should be a write permission. Change it to SD and give it a go. Hope that works.


Comment
Add comment · Show 8 · 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 surfuay · Dec 06, 2018 at 09:41 PM 0
Share

what if there's no SD card?

avatar image Vega4Life surfuay · Dec 06, 2018 at 09:51 PM 0
Share

I believe the internal storage devices are considered SD.

avatar image surfuay · Dec 06, 2018 at 10:01 PM 0
Share

will try it and let you know what happens thanks for the direction either way.

avatar image surfuay · Dec 06, 2018 at 10:01 PM 0
Share

do the write permission need to be anything other than default for iOS too.

avatar image Vega4Life surfuay · Dec 06, 2018 at 10:08 PM 0
Share

Yeah, default is fine for iOS.

avatar image surfuay · Dec 06, 2018 at 10:18 PM 0
Share

yeah, no good i've been going back and forth between internal and SD and still nothing, but it's executing seamlessly in the editor.

avatar image Vega4Life surfuay · Dec 07, 2018 at 12:28 AM 0
Share

Everything looks correct... wow annoying.

avatar image surfuay · Dec 07, 2018 at 01:43 AM 0
Share

BAHAHA! I $$anonymous$$NOW! but that is helpful to know that I have to have the SD for the write permissions. Once I get this figured out that will be a helpful piece of information.

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

101 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

Related Questions

Sharing Violation On Path 1 Answer

Saving and loading game with PlayerPrefs 1 Answer

Problem with saving the transform of the player 1 Answer

How to prevent loading from freezing the game ? 2 Answers

Making A Save Option 1 Answer


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