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
Description
In Distributed Authority, there is an issue with the ownership change of
NetworkTransformthat seems to happen only on theOwnerside.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
Ownerto change the ownership if certain conditions are met, like this:But I don't know if the issue only happen when it's the
Ownerthat useNetworkObject.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 becauseInternalInitializationis not called but should be called.InternalInitializationis supposed to updatebool 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
OnOwnershipChangedI think.NetworkTransform.csOn the first call of
OnOwnershipChangedafter being spawned the output is :previous = 2 current = 2 : m_CachedNetworkManager.LocalClientId = 1previous = 1 current = 2 : m_CachedNetworkManager.LocalClientId = 2The
Ownerdoesn't have the correct previous client id, which should be him.And in the case of
NetworkTransform, it doesn't callInternalInitializationto update theCanCommitToTransformvariable.Environment