I have two classes, genDicTable and StartGame. I want to reference a variable from genDicTable in StartGame, but it yields NULL.
genDicTable.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class genDicTable : MonoBehaviour
{
public TextAsset file;
public double masterCount;
private void Start()
{
Load(file);
masterCount = rowList.Count;
Debug.Log(masterCount); // <-- This properly prints out the value of masterCount
}
public class Row
{
public string id;
public string word;
public string length;
}
public List<Row> rowList = new List<Row>();
public void Load(TextAsset csv) {
// This function assigns a value into RowList
}
}
StartGame.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StartGame : MonoBehaviour {
public genDicTable GEN;
private void Start()
{
Debug.Log(GEN.masterCount); // <-- This yields NULL.
}
}
So, the problem is that when I access the variable masterCount in StartGame.cs, it yields an error "NullReferenceException: Object reference not set to an instance of an object."
What am I missing here?