- Home /
Is it possible to save an object array?
Hello comm-Unity,
So here's my situation: I have an array of objects (not UnityEngine objects, C# ones) that I'm using to store parameters to a function. However, I want to maintain the array in a Monobehavior when I change scenes or reopen Unity. Is there any way to save an object array? Currently I'm editing it through a custom inspector, but when I switch scenes or close Unity, I lose the information. Any help is much appreciated!
Answer by logicandchaos · Jan 27, 2020 at 12:28 AM
You can serialize each entry in the array and convert it to a string in JSON format, then you save it in a text file, this process is supposed to be easier using ScriptableObjects rather than MonoBehaviour, Or it makes sense to have a seperate data only ScriptableObject to save and load data. There are a lot of resources and tutorials on this. Look into scriptable objects and JSON serialize and deserialization, and saving and loading from a text file. There should be some full tutorials for this on youtube and full documentation on the unity site.
Yeah, I ended up going with JSON serialization using JSON.Net. Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220612222159im_/https://answers.unity.com/themes/thub/images/avi.jpg)