Unity Save Edit May 2026

// Save data to the asset data.username = "JohnDoe"; data.score = 100;

// Save the data using binary serialization BinaryFormatter formatter = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/playerdata.dat"); formatter.Serialize(file, data); file.Close(); unity save edit

// Save the updated data EditorUtility.SetDirty(data); AssetDatabase.SaveAssets(); } } // Save data to the asset data

// Load the saved data Debug.Log(data.username); // Output: JohnDoe Debug.Log(data.score); // Output: 100 data.score = 100

// Load the saved data file = File.Open(Application.persistentDataPath + "/playerdata.dat", FileMode.Open); PlayerData loadedData = (PlayerData)formatter.Deserialize(file); file.Close();

[CreateAssetMenu(fileName = "PlayerData", menuName = "PlayerData")] public class PlayerData : ScriptableObject { public string username; public int score; }

// Save the updated data file = File.Create(Application.persistentDataPath + "/playerdata.dat"); formatter.Serialize(file, loadedData); file.Close(); } }

Scroll to Top