Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Network List Not Updating On Clients

Discussion in 'Multiplayer' started by TragicallyCanadian, Nov 27, 2023.

  1. TragicallyCanadian

    TragicallyCanadian

    Joined:
    Mar 26, 2020
    Posts:
    37
    Unity Version: 2022.3.11f1
    Netcode For GameObjects Version: 1.6.0




    Essentially as the title says, updating a network list from the host does not change any information for any of the clients.

    Other notes:
    The Object in question also has additional network variables, several Int's and a string. All of those other variables update with no issue upon being changed from the hosts side.

    If it matters at all, the Network List is a list of Int's. Any ideas? Is this a bug?

    upload_2023-11-27_19-11-7.png
     
  2. TragicallyCanadian

    TragicallyCanadian

    Joined:
    Mar 26, 2020
    Posts:
    37
  3. TragicallyCanadian

    TragicallyCanadian

    Joined:
    Mar 26, 2020
    Posts:
    37
    Update: Bug also present on Netcode For GameObjects Version: 1.7.1
     
  4. TragicallyCanadian

    TragicallyCanadian

    Joined:
    Mar 26, 2020
    Posts:
    37
  5. Lukeesta

    Lukeesta

    Joined:
    Jan 7, 2016
    Posts:
    77
  6. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    247
    You might want to look over the permissions settings for your NetworkVariable(s) in question. If the host is able to make modifications to the NetworkVariable but clients are not, then I would guess that you are using the default server write only permissions.
    • NetworkVariableWritePermission.Server: Only the server can write to the NetworkVariable
    • NetworkVariableWritePermission.Owner: Only the owner can write to the NetworkVariable
    I believe the original design of NetworkVariable was to avoid a "NetworkVariableWritePermission.Everyone" permission as that becomes a much more complex issue to solve for without ending up in race conditions (i.e. client-A and client-B make changes to the list on the same network tick, which change is accepted?).
     
  7. TragicallyCanadian

    TragicallyCanadian

    Joined:
    Mar 26, 2020
    Posts:
    37

    Hey there Noel! Apologies, I think there is a misunderstanding. The problem is not that a client's game cannot write the variable. The problem is that when the owner of the variable updates the list, the update is not reflected on their game object in other player's games.

    For example, if on my player locally, I add to the list, the player object representing me on another client does not have a list reflecting my own, even though I have updated a variable belonging to that gameobject.

    To my understanding, the default permission of reading a network variable is everyone, correct? (I responded on Git and here)
     
  8. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    247
    Ah,
    Well I whipped together a quick example usage of NetworkList that has two NetworkLists in a class called NetworkListTest:
    • m_OwnerNetworkList: The owner is only allowed to write to/modify the list and everyone can read it.
    • m_ServerNetworkList: The server is only allowed to write to/modify the list and everyone can read it.
    The left arrow key removes an entry from the m_ServerNetworkList and the right arrow adds a new entry.
    The up down arrow key removes and entry from the m_OwnerNetworkList and the up arrow adds a new entry.

    Each player spawned will have a unique instance of both NetworkLists relative to each player instance.

    The host can only update each player instance's m_ServerNetworkList.
    Each client (owner) can only update its own player instance's m_OwnerNetworkList.

    I ran a quick test with the example to show the results I am seeing:
    Staring with a host, I added 3 entries to the m_ServerNetworkList and 1 entry to the m_OwnerNetworkList:
    upload_2024-1-7_19-31-16.png
    I then joined 1 client to assure the values synchronized upon the new client joining the session:
    upload_2024-1-7_19-31-57.png
    The new client was synchronized with the host player's NetworkLists with the 3 added entries to m_ServerNetworkList and the 1 entry to m_OwnerNetworkList.
    I then added 2 entries to Client-1's player's m_OwnerNetworkList and 1 more entry to the host's player's m_OwnerNetworkList:
    upload_2024-1-7_19-34-32.png
    You can see that Client-1's 2 new entries are synchronized on the host side instance of Client-1's player and the host's added entry is synchronized on the Client-1 side instance of the host's player.

    Joining a 2nd client all values for both the client and the host values synchronized:
    upload_2024-1-7_19-37-17.png

    I went ahead and attached the example project so you can fiddle around with it to see if there are any differences between the example and your project or if you see something I am not doing in the example that you are doing in your project.

    Let me know if you can replicate the issue using the example project or if it helps you track down the issue in your project?
     

    Attached Files:

    Last edited: Jan 8, 2024
  9. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    247
    As a side note,
    I didn't log the associated client id of each player's m_ServerNetworkList NetworkList instance when the host adds an entry to each one:
    upload_2024-1-7_19-47-45.png
    So, you could add that if you want to make that clearer (otherwise it might seem confusing as to which player's m_ServerNetworkList got which value added).

    But for the m_OwnerNetworkList, I do log which client's instance updated the value on the non-owner's side (so at least that part is less confusing):
    upload_2024-1-7_19-49-25.png
     
    Last edited: Jan 8, 2024
  10. TragicallyCanadian

    TragicallyCanadian

    Joined:
    Mar 26, 2020
    Posts:
    37

    Hey there Noel!

    Thank you for taking the time to set up this example. I now see the issue after comparing your source code with mine. My problem was a syntax issue. And a silly one at that.

    upload_2024-1-8_12-33-33.png
     
    NoelStephens_Unity likes this.