Calling a function with an output that's in another script from a instantiated object

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

If it errors on this line:

string classString = IdChecker.CharClass(thisCharacter.classID);

either IdChecker or thisCharacter is null.

Split it up like this:

var classID = thisCharacter.classID;
string classString = IdChecker.CharClass(classID);

To find out which one it is.

If it’s thisCharacter, it’s because you forgot to assign it in the inspector.
If it’s IdChecker, then the gameObject with the name “GenHandler” doesn’t have a DecodeID component attached.