- Home /
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;
}
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.
I believe the internal storage devices are considered SD.
will try it and let you know what happens thanks for the direction either way.
do the write permission need to be anything other than default for iOS too.
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.
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
Follow this Question
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