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.

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:
    4
    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:
    4
    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:
    426
    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.