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 NetworkList duplicated entries on clients

Discussion in 'Netcode for GameObjects' started by Complex77, Dec 25, 2023.

  1. Complex77

    Complex77

    Joined:
    Feb 28, 2013
    Posts:
    36
    Hey guys! Im trying to implement network lists and for some reason clients are getting duplicated data.
    My list is a networklist of a simple struct

    Code (CSharp):
    1.  
    2. [System.Serializable]
    3. public struct ShipPart : INetworkSerializable, IEquatable<ShipPart>
    4. {
    5.     public FixedString128Bytes ID;
    6.     public int Index;
    7.     public int CurrentArmorPoints;
    8.     public int MaxArmorPoints;
    9.  
    10.     public bool Equals(ShipPart other)
    11.     {
    12.         return other.ID == ID;
    13.     }
    14.     public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
    15.     {
    16.         serializer.SerializeValue(ref CurrentArmorPoints);
    17.         serializer.SerializeValue(ref MaxArmorPoints);
    18.         serializer.SerializeValue(ref ID);
    19.         serializer.SerializeValue(ref Index);
    20.     }
    21. }
    and as you can see on the following screenshots, the server has the correct amount of elements but the client has duplicated data:
    Server:
    upload_2023-12-25_13-33-39.png
    Client:
    upload_2023-12-25_13-33-56.png

    The data is added on the server on networkSpawn of the ship and i was able to consistently reproduce this via the following steps:
    1: Host
    2: Client joins
    3: Server spawns networkobject and on spawn populates the list

    After this, data is desynced between server and client.
    Does anybody know why this is happening andhow to solve it?
     
  2. Complex77

    Complex77

    Joined:
    Feb 28, 2013
    Posts:
    36
    Does anybody use network list with structs?
     
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    676
    I've used them in the past and I had a recollection of seeing duplicated network list data on the client. I did some searching and I mentioned it here, it may not be related to your problem as that seemed to be triggered by a network variable change.

    It might be worth creating a Github issue on it, especially if you can reproduce it in a small project.
     
  4. Complex77

    Complex77

    Joined:
    Feb 28, 2013
    Posts:
    36
    oh.. thats sad, ill see about creating a github issue in the near future.
    in the meantime, what do you use instead? say you need a list of objects that are not necesarelly networkobjects, like maybe a list of ship parts?
    thanks for your reply :) !
     
  5. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    676
    I'd stick with what you're doing if you're happy with it and try figure out the issue. Network lists were reliable last time I checked so it would be good to work out what's wrong as it sounds like a bug that needs fixing.

    I did try replicate what it sounds like you're doing but I don't see the issue. You might have to create that small project or share enough of the project setup and code to be able to reproduce it.
     
    Complex77 likes this.
  6. Complex77

    Complex77

    Joined:
    Feb 28, 2013
    Posts:
    36

    Will do, thanks m8!
     
  7. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    271
    @Complex77
    Not sure if this will help you, but I put together a quick (simple) example of using NetworkLists for another user and you might find this project useful for either creating a replication of the issue you are experiencing or tracking down what the issue might be on your end.

    Also:
    • The INetworkSerializable looks fine to me... so you might provide the script that adds the parts and is logging the information.
    • Also, make sure there isn't any form of static list (or NetworkList for sure) getting both the host and client's parts.
     

    Attached Files:

    Complex77 likes this.
  8. Complex77

    Complex77

    Joined:
    Feb 28, 2013
    Posts:
    36
    Ok, will do so. I did another project to test network lists and I was not able to replicate the issue.
    I'll head back to where my code is breaking to try to understand why they desync.
    Thanks guys