Skip to content

Incorrect value for ulong previous in OnOwnershipChanged on owner side, triggering issue in NetworkTransform #3343

@FureurTime

Description

@FureurTime

Description

In Distributed Authority, there is an issue with the ownership change of NetworkTransform that seems to happen only on the Owner side.
The error message is : Non-owner Client-1 is being updated by network tick still!!!!

If the previous owner gets back the ownership, the error stops.

I use a component that detect collision with the object and request the Owner to change the ownership if certain conditions are met, like this:

public void CheckCollisionFor(GameObject otherGameObject)
{
    if(!HasAuthority && /*some other condition*/)
        RequestOwnershipRpc(NetworkManager.LocalClientId);
}

[Rpc(SendTo.Authority)]
void RequestOwnershipRpc(ulong clientId)
{
    if(HasAuthority && /*some other condition*/)
        networkObject.ChangeOwnership(clientId);
}

But I don't know if the issue only happen when it's the Owner that use NetworkObject.ChangeOwnership() to another client.

The first collision always trigger the issue, but the next collisions seems to be random and not always.

By digging into the code of NetworkTransform, I found the issue is because InternalInitialization is not called but should be called.
InternalInitialization is supposed to update bool CanCommitToTransform, but since it's not called, the value stays to true and triggers the error.

The issue is here, but more generally on all OnOwnershipChanged I think.

NetworkTransform.cs

protected override void OnOwnershipChanged(ulong previous, ulong current)
{
    // If we were the previous owner or the newly assigned owner then reinitialize
    Debug.Log($"[NetworkTransform] ({gameObject.name}) OnOwnershipChanged   previous={previous}, current={current} : {m_CachedNetworkManager.LocalClientId}", this);
    if (current == m_CachedNetworkManager.LocalClientId || previous == m_CachedNetworkManager.LocalClientId)
    {
        InternalInitialization(true);
    }
    base.OnOwnershipChanged(previous, current);
}

On the first call of OnOwnershipChanged after being spawned the output is :

  • On the owner of the object: previous = 2 current = 2 : m_CachedNetworkManager.LocalClientId = 1
  • On the client that triggers the ownership request : previous = 1 current = 2 : m_CachedNetworkManager.LocalClientId = 2

The Owner doesn't have the correct previous client id, which should be him.
And in the case of NetworkTransform, it doesn't call InternalInitialization to update the CanCommitToTransform variable.

Environment

  • OS: Windows 11
  • Unity Version: 6000.0.32f1
  • Netcode Version: 2.2.0

Metadata

Metadata

Labels

priority:highThis issue has high priority and we are focusing to resolve itregressionThe issue is a regression (something that was working in previous version)stat:importedStatus - Issue is tracked internally at Unitytype:bugBug Report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions