Hey!
My game is using Distributed Authority and I’m getting a 100% desync on networkVariables with the code below (setting the netVar and changing ownership immediately after).
public class TestNetBehaviour : NetworkBehaviour
{
private readonly NetworkVariable<int> m_TestNetVarInt = new(0, writePerm: NetworkVariableWritePermission.Owner, readPerm: NetworkVariableReadPermission.Everyone);
void Update()
{
if (Keyboard.current.spaceKey.wasPressedThisFrame && HasAuthority && IsSpawned)
{
m_TestNetVarInt.Value++; // netVar is incremented on the owner but won't be synced to other clients (at least not to the new owner)
NetworkObject.ChangeOwnership(someRemoteClientId);
}
}
}
m_TestNetVarInt will be incremented on the current owner, but won’t be synced to the new owner. I assume the ownership change is happening first and the netVar update gets rejected.
Is there a way to protect agains this happening?
Thanks!