How to Fix this issue
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
public class ObjectiveList : MonoBehaviour {
public ObjectiveList obj;
public Text objList;
public List<Objective> objectives = new List<Objective>();
void Start() {
obj = FindObjectOfType<ObjectiveList>();
obj.CreateObjective ("obj1", "Enter the palace.");
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player") {
obj.CompleteObjective ("Obj1");
}
}
void Update()
{
objList.text = "";
Objective[] objArray = objectives.ToArray();
for (int i=0; i < objectives.Count; i++)
{
Objective test = objectives[i];
if(!test.completed)
objList.text += (i+1)+ "." + objArray[i].objective + "\n";
else
objList.text += (i + 1) + ".<b><color=green>" + objArray[i].objective + "</color></b>\n";
}
}
public void CreateObjective(string shortName, string objText)
{
objectives.Add(new Objective(shortName, objText, false));
objectives.Sort();
}
public void CompleteObjective(string objName)
{
Objective selected = objectives.Find(x => x.identifier.Contains(objName));
selected.completed = true;
}
public void RemoveObjective(string objName)
{
objectives.Remove(objectives.Find(x => x.identifier.Contains(objName)));
}
}
NullReferenceException: Object reference not set to an instance on an object ObjectiveList.Update () (at Assets/ASCore/Scripts/ObjectiveList.cs:25
Answer by TBruce · May 22, 2016 at 02:37 AM
When posting code, please do not post screen shots. People can not help much that way. Please format ALL you code properly and paste the code directly into the body of the question. To do that copy the code to your clipboard and press the "101010" button in the toolbar of the UA text editor. This will format the code so it can be easily read in the forum.
But I would say your problem is that
public text objList;
has not been set in the inspector and therefore is null. so when you go to use is you will get a NullReferenceException error.
@$$anonymous$$avina How can I set it into the inspector to fix this problem?
Your answer
Follow this Question
Related Questions
CameraController (object reference not set to an instance of an object) 1 Answer
Object reference not set to an instance of an object [problem with Unity 5] 2 Answers
MonoDevelop Unity API reference function with wrong path. How to Fix it? 1 Answer
Can't access a method from another script (Object reference not set to an instance of an object) 1 Answer
NullReferenceException: Object reference not set to an instance of an object 3 Answers