Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Network List error and NetworkList.Count is 0 on the client build

Discussion in 'Netcode for GameObjects' started by TheUnaverageJoe, Oct 8, 2022.

  1. TheUnaverageJoe

    TheUnaverageJoe

    Joined:
    Aug 25, 2019
    Posts:
    3
    Hi, to preface this question, I don't really know what the problem is. I've looked through the documentation on NetworkLists as well as the forums but haven't seen anything with quite the same error, any help is appreciated. I'm trying to use a custom data type PlayerLobbyData in a NetworkList but I'm getting an error after the client joins the host. It continues to produce the error while the host(Unity Editor) is running.
    The struct I made is attatched

    ***ERROR MESSAGE BELOW***

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. Unity.Netcode.NetworkVariableSerialization`1[T].GetSerializer () (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/NetworkVariable/NetworkVariableSerialization.cs:239)
    3. Unity.Netcode.NetworkVariableSerialization`1[T]..cctor () (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/NetworkVariable/NetworkVariableSerialization.cs:217)
    4. Rethrow as TypeInitializationException: The type initializer for 'Unity.Netcode.NetworkVariableSerialization`1' threw an exception.
    5. Unity.Netcode.NetworkList`1[T].WriteDelta (Unity.Netcode.FastBufferWriter writer) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/NetworkVariable/Collections/NetworkList.cs:93)
    6. Unity.Netcode.NetworkVariableDeltaMessage.Serialize (Unity.Netcode.FastBufferWriter writer) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs:94)
    7. Unity.Netcode.MessagingSystem.SendMessage[TMessageType,TClientIdListType] (TMessageType& message, Unity.Netcode.NetworkDelivery delivery, TClientIdListType& clientIds) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Messaging/MessagingSystem.cs:492)
    8. Unity.Netcode.MessagingSystem.SendMessage[T] (T& message, Unity.Netcode.NetworkDelivery delivery, System.UInt64 clientId) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Messaging/MessagingSystem.cs:612)
    9. Unity.Netcode.NetworkManager.SendMessage[T] (T& message, Unity.Netcode.NetworkDelivery delivery, System.UInt64 clientId) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Core/NetworkManager.cs:1871)
    10. Unity.Netcode.NetworkBehaviour.NetworkVariableUpdate (System.UInt64 targetClientId, System.Int32 behaviourIndex) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Core/NetworkBehaviour.cs:653)
    11. Unity.Netcode.NetworkBehaviour.VariableUpdate (System.UInt64 targetClientId) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Core/NetworkBehaviour.cs:602)
    12. Unity.Netcode.NetworkBehaviourUpdater.NetworkBehaviourUpdate (Unity.Netcode.NetworkManager networkManager) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Core/NetworkBehaviourUpdater.cs:51)
    13. Unity.Netcode.NetworkManager.OnNetworkManagerTick () (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Core/NetworkManager.cs:1604)
    14. Unity.Netcode.NetworkTickSystem.UpdateTick (System.Double localTimeSec, System.Double serverTimeSec) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Timing/NetworkTickSystem.cs:102)
    15. Unity.Netcode.NetworkManager.OnNetworkPreUpdate () (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Core/NetworkManager.cs:1568)
    16. Unity.Netcode.NetworkManager.NetworkUpdate (Unity.Netcode.NetworkUpdateStage updateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Core/NetworkManager.cs:1476)
    17. Unity.Netcode.NetworkUpdateLoop.RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage updateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Core/NetworkUpdateLoop.cs:185)
    18. Unity.Netcode.NetworkUpdateLoop+NetworkPreUpdate+<>c.<CreateLoopSystem>b__0_0 () (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.1/Runtime/Core/NetworkUpdateLoop.cs:232)
    19.  
     

    Attached Files:

  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    610
    This was an issue not so long ago but I think was fixed in the version you're using. Try the latest version of Netcode in case there have been other fixes.
     
  3. TheUnaverageJoe

    TheUnaverageJoe

    Joined:
    Aug 25, 2019
    Posts:
    3
    I believe I am using the latest, Version 1.0.2 - September 13, 2022.
     
  4. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    610
    The issue looks to be the implementation of NetworkSerialize, try:
    Code (CSharp):
    1. public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
     
  5. TheUnaverageJoe

    TheUnaverageJoe

    Joined:
    Aug 25, 2019
    Posts:
    3
    That seems to have done the trick thank you! Yesterday I tried this but It was showing errors in VScode, and today it worked with no problems. Maybe I forgot to try this after updating NGO.
     
    cerestorm likes this.