I’ve used FromJson in Unity/C# a dozen occasions, and but for some purpose I am unable to determine why this one would not work.
Right here is the code that performs the evaluation:
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).identify);
}
}
The lessons are outlined like this:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
(System.Serializable)
public class FaultModule
{
public string identify;
public int gracePeriod;
public float multiplier;
public int cooldown;
}
public class FaultModules
{
public FaultModule() modules;
}
And the JSON seems to be like this:
{ "FaultModules": (
{
"identify": "genericFaultModule",
"gracePeriod": 10,
"multiplier": 0.8,
"cooldown": 40
},
{
"identify": "otherGenericFaultModule",
"gracePeriod": 15,
"multiplier": 2,
"cooldown": 50
}
) }
The compiler would not throw any errors and the jsonFile var completes appropriately, however when the Debug line is executed, it says that the item reference is just not set to an occasion of an object. I’ve a sense it is one thing easy like a lacking semicolon, however for the lifetime of me I am unable to see it.
The one clue I’ve is that although I used (SerializeField) in fallList, it would not seem within the Inspector.