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

Bug NetworkVariable Abstract class error

Discussion in 'Netcode for GameObjects' started by qenious, Apr 23, 2024.

  1. qenious

    qenious

    Joined:
    Feb 11, 2022
    Posts:
    9
    Hi everyone. I'm developing a Online - Mobile game and I use Netcode. Here are my code samples. So my problem is, when I use NetworkVariable with abstract class, it's throwing
    Code (CSharp):
    1. Null Reference Exception
    . I gave my 2 - 3 days for this little problem. And there is no exception catch info or something like that. So, I think this is a serious bug with NetworkVariable between inhereted classes. Please if I'm wrong let me know, or just write your opinion. Have a nice coding everyone !
     

    Attached Files:

    • 1.png
      1.png
      File size:
      22.4 KB
      Views:
      9
    • 2.png
      2.png
      File size:
      10.5 KB
      Views:
      9
    • null.png
      null.png
      File size:
      6.6 KB
      Views:
      9
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,659
    First, code is text so please post it as text, and put it in code tags.

    Secondly, there's not nearly enough code to diagnose your issue. None of the classes you screenshotted is abstract. And the error message should have more details than just the first line, it points you directly to the line in question. Also, no mention of when or under which circumstances the exception occurs.

    Thirdly, don't just assume it's a "serious bug". It's more likely going to vanish after a serious facepalm. ;)
     
  3. qenious

    qenious

    Joined:
    Feb 11, 2022
    Posts:
    9
    I'm sorry, it wasn't about Abstract classes. It's about Inhereted classes. When I create Inhereted class and write a NetworkVariable in it, when game start, it's giving NullReferenceException .
     

    Attached Files:

    • new.png
      new.png
      File size:
      74.4 KB
      Views:
      6
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,659
    Again, do not screenshot code but copy the code as text!
    Post all the relevant code, including PlayerData and the full error message (Console has a details pane and ctrl+c works in there too).

    Note that if you intend to add all possible player state into PlayerData, then every time any of these values changes a full transfer of the entire state is performed which is increasingly inefficient the more fields you have in that PlayerData. Primarily networking is about reducing how much state is synchronized as much as possible.