Scriptible Object Saving
Hello I am kinda new to making games so please post your answers as simple as possible .Am having problems when am trying to save my scriptible object data. Everything works fine unitil i reload the Unity. All the integer data is still here but Sprites don't load in.... Before:
And after i reload Unity
This is my saving script:
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Runtime.Serialization.Formatters.Binary; using System.IO;
public class PersistableSO : MonoBehaviour {
[Header("Meta")]
public string persisterName;
[Header("Scriptable Objects")]
public List<ScriptableObject> objectsToPersist;
protected void OnEnable()
{
for (int i = 0; i < objectsToPersist.Count; i++)
{
if (File.Exists(Application.persistentDataPath + string.Format("/{0}_{1}.pso", persisterName, i )))
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + string.Format("/{0}_{1}.pso", persisterName, i ), FileMode.Open);
JsonUtility.FromJsonOverwrite((string)bf.Deserialize(file),objectsToPersist[i]);
file.Close();
} else
{
//Do Nothing
}
}
}
protected void OnDisable()
{
for (int i = 0; i < objectsToPersist.Count; i++)
{
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + string.Format("/{0}_{1}.pso", persisterName, i ));
var json = JsonUtility.ToJson(objectsToPersist[i]);
bf.Serialize(file, json);
file.Close();
}
}
}
Your answer
Follow this Question
Related Questions
Issues when loading sub assets from an AssetBundle 0 Answers
Is there any way to recreate the executable? 0 Answers
reading and writing files in built project,Files 0 Answers
I have as background a picture unity 3d but i want to put it so the player can never reach it ? 1 Answer
UnityEngine.GameObject does not contain a definition for getComponent 1 Answer