Hey guys, Ive been trying to figure out why my code doesnt work for a couple of hours and I just cant fin the misstake:
QuestData newQuest = JsonUtility.FromJson<QuestData>(Resources.Load<TextAsset>("Data/QuestData").text);
for (int i = 0; i > newQuest.quests.Length; i++)
{
questDatabase.Add(newQuest.quests[i].id, newQuest.quests[i]);
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class Quest
{
public int id;
public string questName;
public string description;
public int recipient;
public Reward reward;
public Task task;
[Serializable]
public class Reward
{
public float exp;
public float gold;
public QuestItem[] items;
}
[Serializable]
public class Task
{
public int[] talkTo;
public QuestItem[] items;
public QuestKill[] kills;
}
[Serializable]
public class QuestItem
{
public int id;
public int amount;
}
[Serializable]
public class QuestKill
{
public int id;
public int amount;
public int playerCurrent;
}
}
[Serializable]
public class QuestData
{
public Quest[] quests;
}
{
"quests":[
{
"id": 0,
"questName": "QuestName of Quest 0",
"description": "Description of Quest 0",
"recipient": 0,
"reward": {
"exp": 100.0,
"gold": 50.0,
"items": []
},
"task": {
"talkTo": [],
"items": [],
"kills": [{
"id": 0,
"amount": 10,
"playerCurrent": 0
}]
}
},
{
"id": 1,
"questName": "QuestName of Quest 1",
"description": "Description of Quest 1",
"recipient": 0,
"reward": {
"exp": 100.0,
"gold": 50.0,
"items": []
},
"task": {
"talkTo": [],
"items": [],
"kills": [{
"id": 0,
"amount": 10,
"playerCurrent": 0
}]
}
}
]
}
if i Debug the following: “Resources.Load(“Data/QuestData”).text” I get the Data from my Jsonfile
If I debug “JsonUtility.FromJson(Resources.Load(“Data/QuestData”).text)” I get the error “NullReferenceException: Object reference not set to an instance of an object”
What am I overlooking?