I’ve used FromJson in Unity/C# a dozen occasions, and but for some motive I can not determine why this one’s not working.
Here is the code that does the parsing:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing System.IO;
utilizing UnityEngine;
public class ModuleSpawnScript : MonoBehaviour
{
TextAsset jsonFile;
[SerializeField]
FaultModules faultList = new FaultModules();
void Begin()
{
jsonFile = Assets.Load("JSON/FaultModules");
faultList = JsonUtility.FromJson(jsonFile.textual content);
Debug.Log(faultList.modules[0].title);
}
}
The courses are outlined like so:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
[System.Serializable]
public class FaultModule
{
public string title;
public int gracePeriod;
public float multiplier;
public int cooldown;
}
public class FaultModules
{
public FaultModule[] modules;
}
And the JSON seems like this:
{ "FaultModules": [
{
"name": "genericFaultModule",
"gracePeriod": 10,
"multiplier": 0.8,
"cooldown": 40
},
{
"name": "otherGenericFaultModule",
"gracePeriod": 15,
"multiplier": 2,
"cooldown": 50
}
] }
The compiler does not throw any errors, and the jsonFile var populates appropriately, however when the Debug line runs, it says that the thing reference is not set to an occasion of an object. I get the sensation that it is one thing easy like a lacking semicolon, however for the lifetime of me I do not see it.
The one clue I’ve is that though I used [SerializeField] on faultList, it does not present up within the Inspector.