Network.connection.identiy check in update

So does anyone know why in the lecture, the below code works in the update method but mine kept throwing a null reference exception on the NetworkClient.connection.identity?

I’m working in Unity 2020.2.2

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

My work around to get it to work was add it in the LateUpdate method and add the AND check,

 private void LateUpdate() 
    {
        if (player == null && NetworkClient.connection.identity != null)
        {
            player = NetworkClient.connection.identity.GetComponent<RTSPlayer>();
        }
    }
1 Like

Hi there,

This is a known issue, it only occurs for some people so it’s hard to nail down. Your solution is a good one, I think there is a race condition there perhaps.

1 Like

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

Privacy & Terms