Cannot get the game over logic to work. Null reference

I think it’s dying before it has a chance to do anything, because I’m getting a null reference exception when I kill the base. It’s pointing me to UnitSelectionHandler , and seems to be complaining about

if(player == null)
{
player = NetworkClient.connection.identity.GetComponent();

Has anyone done whatever my mistake was and can help me with this? I’m dying here. Not being able to get this fixed has made me stop progressing in the course and stop trying really.

Hi,

Normally I drop in a few debug.log statements to figure out which reference is null. In this case I would check NetworkClient, NetworkClient.connection and NetworkClient.connection.identity.

Is this error only occurring when you a base, or is it happening when you load the game?

What happens when you destroy the abse?

I set a breakpoint to try and catch when it was happening. It actually looks like it’s happening when the game is loading. But it’s not stopping the game from functioning, so I think that was just a red herring.

I can spawn units, and when I hit them their health increments down, and 5 hits calls their objects to be destroyed. I can destroy tanks and bases. But for some reason the base destruction isn’t calling what I am expecting, which is the GameOverHandler / GameOverDisplay scripts. Maybe I just don’t have something connected to a unit on the Unity side, or something like that.

Okay, so the error is probably not related to the game over issues.

Let’s try and narrow down how far it’s getting. Make sure the health is connected to the UnitBase on the unit base prefab. Then try putting some debug statements in the following methods:

UnitBase.cs ServerHandleDie()
UnitBase.cs OnStopServer()
GameoverHandler.cs ServerHandleBaseDespanwed()
GameoverHandler.cs RpcGameOver
GameOverDisplay.cs ClientHandleGameOver()

Sorry it has taken me so long to get this and respond. Finally got debug.log lines in each of these spots. Also verified that the HEALTH script is attached to the unitbase prefab. Ran it and destroyed a base. The only debug lines that made it in are:

UNITBASE ONSTOPSERVER (logged 2x for some reason)
UNITBASE ONSERVERHANDLEDIE (1 time)

So none of the gameoverhandle scripts are even being called. Would that imply that they are not referenced where they should be in a script themselves? Or perhaps not attached to a prefab or linked correctly on the prefab or script reference inside unity?

Arrrgggghh!@!@!@

Thank you for the continued help.

Well the gameOverHandler and the Unit base are connected by the ServerOnBaseDespawned event.
image
In your gameOverHandler, double check these subscription statements.

Did you place the debug.log at the top of the ServerHandleBaseDespawned method?

My gameoverhandler does have these, but I didn’t have an OnDestroy. I added that but it didn’t do anything. When the scene loads, I do have a GameOverHandler(Clone) that’s part of the scene, and it does have the Game Over Handler script on it. It just doesn’t seem to be getting called by anything.


You have a spelling mistake in your subscription statements.
You are missing the “De” in Despawned in the the second statement in both OnStartServer and OnStopServer.

UnitBase.ServerOnBaseDespawned += ServerHandlerBaseDespawned

Good lord. That did it.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms