Changing ownership of distributed object causes NetworkVariable to desync

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!

Since you can replicate this and it looks like a bug, it’s worth reporting, use Help => Report a bug.

Hey, thanks for reporting this and providing a code snippet.

I’ve just replicated this issue locally and will look into it further!

I’ve raised a bug internally for this and will keep you posted on its progress :slight_smile:

Update - we’ve got a fix for this which will be included in the next update

Thanks for looking into this so quickly!