Hello everybody,
I am having some trouble when trying to call a function in another script with a return value from a instantiated object.
The call is to a function that will return a string when passed an int, however I just get the error:
“NullReferenceException: Object reference not set to an instance of an object”
when the function is called.
Heres a basic outline of my code:
public class RecruitableCharacter : MonoBehaviour
{
GameObject genCaller;
DecodeID IdChecker;
public Character thisCharacter;
void Start()
{
genCaller = GameObject.FindWithTag("GenHandler");
IdChecker = genCaller.GetComponent<DecodeID>();
}
public void updateVisuals()
{
string classString = IdChecker.CharClass(thisCharacter.classID);
gameObject.transform.Find("Class").gameObject.GetComponent<Text>().text = classString;
}
}
The error is when IdChecker.CharClass is called, which should just return an string when it is passed a int. thisCharacter.classID is a int which has already been set.
RecruitableCharacter is attached to the prefab that gets instantiated.
I am unsure why this does not work, as I am able to call other functions in the same way but whenever the function has a return parameter it does not work and I get this error.
Thanks for your help