I know the title is a bit confusing because I don't really know how to phrase this. This is what I have:
[System.Serializable]
public class Sector
{
public string name;
public Vector3 sectorPosition;
public float sectorRadius;
public buildingComponent[] components;
}
[System.Serializable]
public class buildingComponent : ScriptableObject
{
public string componentType;
public Vector3 componentPosition;
public Vector3 compenentRotation;
}
When I try converting this into a json string like this:
Sector ssector = new Sector();
ssector.name = "sTom";
ssector.sectorPosition = Vector3.up;
ssector.sectorRadius = 2;
ssector.components = new buildingComponent[3];
print("component length " + ssector.components.Length);
ssector.components[1] = new buildingComponent();
ssector.components[1].componentPosition = new Vector3 (1, 2, 3);
string sdata = JsonUtility.ToJson(ssector);
I end up with the following:
{"name":"sTom","sectorPosition":{"x":0.0,"y":1.0,"z":0.0},"sectorRadius":2.0,"components":[{"instanceID":0},{"instanceID":-341752},{"instanceID":0}]}`
The components array is not actually being formatted, it's only saved with an instanceId or whatever this does. Is there any solution to this or will I have to go with an alternative formatting. I just want to save this data on a server but I only get one string to do so, so I have to format everything into one string. Thanks in advance!