Null Reference Exception for RTSPlayerScript

In lecture 20 the following was added to private void Update.

        if (player == null)
        {
            player = NetworkClient.connection.identity.GetComponent<RTSPlayerScript>();
        }

While this throws the null reference error I used to be able to unpause and let it run. It no longer allows me to do that so I am unable to test the game. I looked in the questions and someone had said they were able to pause it but gave no indication as to how. I haven’t been able to test the game in two player mode for the past 7 lectures. There needs to be a way around this but I just don’t know what it is. I am using Unity 2020.1.11f1

Hi There, can you try adding a second check for the NetworkClient.connection. Please let me know if this works. This is in update in UnitSelectionHandler, correct?


if (player == null && NetworkClient.connection != null)
    {
     player = NetworkClient.connection.identity.GetComponent<RTSPlayer>();
    }
2 Likes

Yitzchak,
Thank you for your reply and your help. I appreciate it. I no longer get the error which is great! As an FYI for anyone who may have the same issue, I did find out late last night that I was trying to “play” the game while in Scene_Map_01 scene. That was the root of my personal evil. When I changed scenes to the Scene_Menu scene and "play"ed the game I was able to get past the error. I had been fiddling with prefabs or connecting different scripts to them as per the lectures and I didn’t realize what scene I was actually in.

Again thank you for your help.
Cheers!

1 Like

Privacy & Terms