Null Reference When Method is Called from Another Script

Hi, all.

I have a GameController script that doesn’t destroy itself on load and therefore traverses across some scenes. Upon loading the main game scene, it is ordered to get a reference to a UI controller for that scene that is already an instance in that scene.

I debugged all of that and it works fine. The reference is there.

When the player hits an object, that object calls a function on the Game Controller, which in turn tries to call a function on the UI controller.

However, I get a null reference exception every time the game controller tries to call a method on this object (Which both exists and is definitely a reference)

What gives? I can post code if needed.


I’m sorry. Perhaps I have come off as if I am much less experienced than I actually am. I completely understand the application of the static keyword, problems of scope, and component references.

My GameController exists in another scene and isn’t destroyed on load. When it loads the new scene up, it looks for the GameView object that exists in the loaded scene. However, when I try to call a function on this referenced object, nothing ever happens.

An interesting thing to note:
If, when I try to call the function, I immediately search for this GameView object and then call the function in-line like so:


It works just fine. However, if I update the reference and then call it, it won’t work:

gameView = GameObject.Find("GameView").GetComponent<GameView>();

Where gameView is a private variable of type GameView on the script trying to reference it.

What gives?