Greetings, I’ve run into some issues that I cant see to understand, hopefully someone will enlighten me
ScriptA, existing on 3-4 other objects, each holds its his own List.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ScriptA : MonoBehaviour
{
//declares the List, interacting with the List from within the script works just fine
public List<string> List_StartingField = new List<string>();
Start () {}
Update(){}
//etc.
//will later do something with the content of its List, not yet implemented since I have errors.
}
The ScriptB on a Manager Object which is supposed to Add something to the List_StartingField List in ScriptA
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class ScriptB : MonoBehaviour
{
ScriptA scriptA0;
void Start ()
{
ScriptA scriptA0 = GameObject.Find("ScriptAs ObjectName").GetComponent<ScriptA>();
}
void AddSomethingToStartingFieldList()
{
if (!scriptA0.List_StartingField.Contains(variableToAdd)) //trying to access the List throws the NullReferenceErrors
scriptA0.List_StartingField.Add(variableToAdd);
}
}
Everything compiles fine, but once I hit the Play button I’ll get a “NullReferenceException: Object reference not set to an instance of an object” to the console whenever I try to access the List from ScriptB, be it with Debug.Log or .Add().