Hello! I’m having trouble copying a list over to a dictionary. When I do I get a null reference exception even though the list is not empty.
public Dictionary<string, List<GameObject> > interestPoints;
public List<string> rooms = new List<string>();
...
GameObject[] ipoints = GameObject.FindGameObjectsWithTag("InterestPoint");
List<GameObject> tempIps = new List<GameObject>();
for(int i = 0; i < rooms.Count; i++){
tempIps.Clear();
foreach(GameObject ip in ipoints){
// Check which ip is in which room by checking its name
if(ip.name.EndsWith(rooms[i])){
tempIps.Add(ip);
Debug.Log(tempIps[0].name);
}
}
// Add the ips from the temp ips to the correct room
if(tempIps.Count > 0){
Debug.Log("There are " + tempIps.Count + " Interest points in " + rooms[i]);
interestPoints.Add(rooms[i], tempIps); // null reference exception
}
}
Hope someone care to help!
Cheers!