Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug NetworkList initially sync not triggering OnListChanged when there is latency

Discussion in 'Netcode for GameObjects' started by dave12490182401284, Sep 4, 2022.

  1. dave12490182401284

    dave12490182401284

    Joined:
    Aug 17, 2022
    Posts:
    5
    I have a `NetworkList`. Which is syncing and working normally across host/clients when updated (value added or removed) while all clients are connected.

    `OnListChanged` is triggered on all clients whenever the `NetworkList` is updated.

    However in this situation:
    - Host starts game and updates the `NetworkList`
    - Client joins late with some latency, for example 200ms (after `NetworkList` already has values)
    - Clients initially has an empty `NetworkList` on connect, and when it does get the initial sync update it does not trigger the `OnListChanged`

    So how can I determine when the client has received the initial sync values? The only way I can think of is to have a hackish timer that keeps checking the network value manually.
     
  2. dave12490182401284

    dave12490182401284

    Joined:
    Aug 17, 2022
    Posts:
    5
    I think I've found the issue that I was binding the `OnListChanged` listeners within the `Start` method, if I move binding the listeners into the `OnNetworkSpawn` method it seems to solve the issue.
     
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    653
    OnNetworkSpawn does seem to best place to register OnListChanged and OnValueChanged callbacks. There have been issues with network lists not correctly syncing with clients on spawn, and there's an outstanding issue where a network list can be sent twice by the server, once on spawn and then as OnListChanged events leading to the client list having double the content it should have.
     
  4. JJRivers

    JJRivers

    Joined:
    Oct 16, 2018
    Posts:
    137
    Oh? Any recollection on where this issue is listed? I've been fighting with the NetworkList for most of a day now and the damned thing seems to spoof some magical entries into it, only present clients are Host+Client and each adds itself to the list via a ServerRpc in OnNetworkSpawn and the end result is that the Host has a correct list (two elements with correct data) while the Client has three entries, one for the Host and two for the Client. Meaning the list is not synchronized or reliable in any meaningful manner.
     
  5. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    I do the same and it works. Can you post your code?
     
  6. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    653
    I mentioned it in this issue here https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/2156 but it looks like it wasn't reproduced and I coded out the issue, I can't remember what code caused the problem.

    If you're on the latest version of Netcode and are seeing this you might want to create a new issue for it.

    Oh I remember a little more now the network list was being re-sent when I changed a network variable value in the same object, very bizarre behaviour and I'm not sure it's related.
     
    lavagoatGG likes this.