0

I'm using unity and need to save some names in a JSON text to usem them later as listed in this class

[System.Serializable]
public class EnemyData
{
    public string EnemyName;
}

And the function that is using is this:

public async Task SaveEnemyData(List<EntityScript> EnemyEntitys)
{
    EnemyData enemyData = new EnemyData();
    foreach (EntityScript ENemy in EnemyEntitys)
        enemyData.Add(ENemy.Nome);
    string TempEnemyData = JsonUtility.ToJson(enemyData);
    File.WriteAllText(Application.dataPath + "/Scripts/Combat System/Prebattle/JSON EnemyData/TempEnemyData.txt",TempEnemyData);
    while (!File.Exists(Application.dataPath + "/Scripts/Combat System/Prebattle/JSON EnemyData/TempEnemyData.txt"))
    {
        Debug.Log("Creating File...");
        await Task.Yield();
    }
    Debug.Log("Enemys Saved for now");

But for some reason this is causing a null reference

0 Answers0