Search Unity

Variable constantly replicated

Discussion in 'Netcode for GameObjects' started by ElliotB, Mar 26, 2022.

  1. ElliotB

    ElliotB

    Joined:
    Aug 11, 2013
    Posts:
    289
    Hi,

    I'm currently having some difficulty with a NetworkVariable that seems to never-endingly replicate. If I log data from the OnValueChanged delegate, it shows that both the previous and current values are identical. e.g. logging crudely with
    Code (CSharp):
    1. Debug.Log("NetworkObject " + _Weapon.Vehicle.NetworkObjectId + ", Owner + " + _Weapon.OwnerClientId + ":_Weapon.Selected.OnValueChanged:" + prev + "," + next);
    I find my console is flooded with messages like
    upload_2022-3-26_21-28-24.png
    which has the same value for both prev and next (separate question - why was OnValueChanged invoked if the value did not change?)

    The amount of replication steadily increases, until NetworkEarlyUpdate takes long enough that the client completely freezes:


    I must be doing something wrong, but I've been looking a while and haven't made any progress. I do have something subscribed to OnValueChanged, and I wondered if having an exception in that callback would somehow cause replication to fail and for the server to try to send again (is that possible?). However, after disabling those callbacks I wasn't able to find any clues.

    Any thoughts would be greatly appreciated.

    Cheers,
    Elliot
     
  2. ElliotB

    ElliotB

    Joined:
    Aug 11, 2013
    Posts:
    289
    After digging further, I found that the error only occurs for a server with two clients. For a server with one client, the error never occurs. I also found that this is the only NetworkVariable in my project with NetworkVariableReadPermission.OwnerOnly. After removing that permission the error no longer occurs. This looks like a netcode bug, where NetworkVariableReadPermission.OwnerOnly causes replication to fail and repeatedly drive OnValueChanged events?
     
  3. Helliaca

    Helliaca

    Joined:
    May 26, 2016
    Posts:
    2
    I have the same issue.

    It seems to happen whenever an owner that isn't the server sets the value of a NetworkVariable.
    It also only occurs on all clients *except* the first (the host) and the last that joined.

    I've managed to circumvent the issue by having all NetworkVariables with
    NetworkVariableWritePermission.Server
    and setting the values through an RPC. But whats the point of having Owner-only write permissions if we can't use them?