I’m working on a little tool that lets me connect several GameObjects with a LineRenderer. It’s possible to connect multiple objects within one line. To store the Data of every connection, I’m saving the GameObject.name of every point in the connection in an array (string[ ]). Serializing this array as JSON worked without problems.
Next step is to store multipe Lines in a list of arrays (List<string[ ]>) and store it as JSON, so I can deserialize all my Lines at once.
Here is what I’m doing:
public ConnectionCollectionObject activeCollection; // <- This one is filled by the user by clicking things in the scene
public void SaveConnectionCollection()
{
if (activeCollection == null) return;
Debug.Log(JsonUtility.ToJson(activeCollection, true)); // result: {}
string path = Path.Combine(Application.persistentDataPath, id + "_ConnectionCollection.json");
File.WriteAllText(path, JsonUtility.ToJson(activeCollection, true));
Debug.Log(path + " saved.");
}
/////////
[Serializable]
public class ConnectionCollectionObject
{
public List<string[]> connectionCollection;
}
…using the same princple like I used when serializing the string[ ] gives ony an empty .json file.