Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Object reference error when trying to update networkvariable after a client disconnects

Discussion in 'Netcode for GameObjects' started by sadzanenyama, Dec 24, 2023.

  1. sadzanenyama

    sadzanenyama

    Joined:
    Dec 9, 2015
    Posts:
    9
    If I have several clients connected to a server and then one of the clients leave than anytime I try to update (using OnValueChanged) any networkvariable on any of the clients still connected an object reference error occurs.

    upload_2023-12-25_1-55-55.png

    There are no issues if there is just one client and no one disconnects, it will update completely fine. Also if all the clients disconnect and then reconnect the error stops again. I am completely stumped.
     
  2. sadzanenyama

    sadzanenyama

    Joined:
    Dec 9, 2015
    Posts:
    9
    I was using a static function to update a network variable from another script. That ended up being the problem.
    Weird cause even if that section of the code was never called it still threw the above error, updating any networkvariable (any non static ones) would cause it. Seems when one network variable is called, the OwnerClientID is checked on all network variables. No clue though, this is far from my area of expertise, just happy I figured it out.