Skip to content

fix: owner changing ownership causing identical previous and current ids when using a distributed authority network topology #3347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

NoelStephensUnity
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity commented Mar 13, 2025

This fixes an issue with the synchronization of NetworkVariables when changing ownership where it was possible to have the previous owner be equal to the current owner when using a distributed authority network topology and the owner handled changing the ownership.

This includes an additional check for ditry states of any collections base NetworkVariables.

fix: #3343
close: #3343

Changelog

  • Fixed issue where an owner that changes ownership, when using a distributed authority network topology, could yield identical previous and current owner identifiers. This could also cause NetworkTransform to fail to change ownership which would leave the previous owner still subscribed to network tick events.

Testing and Documentation

  • Includes integration test NetworkObjectOwnershipTests.TestAuthorityChangingOwnership.
  • No documentation changes or additions were necessary.

This fixes an issue with the synchronization of NetworkVariables when changing ownership where it was possible to have the previous owner be equal to the current owner when using a distributed authority network topology and the owner handled changing the ownership.

This includes an additional check for ditry states of any collections base NetworkVariables.

This bug was introduced as a regression bug when resolving the issue that any owner read permission NetworkVariables were fully synchronized with the new owner.
adding a change log entry.
@unity-cla-assistant
Copy link

unity-cla-assistant commented Mar 13, 2025

CLA assistant check
All committers have signed the CLA.

@NoelStephensUnity NoelStephensUnity changed the title fix: owner changing ownership causing identical previous and current ids when using a distribute authority network topology fix: owner changing ownership causing identical previous and current ids when using a distributed authority network topology Mar 13, 2025
@NoelStephensUnity NoelStephensUnity changed the base branch from develop to develop-2.0.0 March 13, 2025 19:03
Fixing issue where we need to reset the OwnerId and PreviousOwnerId after running through NetworkBehaviourUpdate to assure the values are properly set when there are no dirty objects to reset.
Updating change log entry and adding PR number.
Fixing an order of operations issue with synchronizing owner read permission NetworkVariables.
adding a test to validate this specific issue where the authority changes the ownership.
{
if (NetworkManager.LogLevel <= LogLevel.Developer)
{
Debug.LogWarning($"[{nameof(NetworkSpawnManager)}][{nameof(ChangeOwnership)}] Attempting to change ownership to Client-{clientId} when the owner is already {networkObject.OwnerClientId}! (Ignoring)");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is already happening on line 524 of this function, though the check is a little different:

if (networkObject.OwnerClientId == clientId && networkObject.PreviousOwnerId == clientId)

We should probably consolidate the two checks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was that there are several places that invoke NetworkSpawnManager.ChangeOwnership:
image
I decided to put a check at the funnel point. However, at some point in the future we might look at all of the invocations to determine if it makes sense to consolidate the various checks for this condition... for now we know that we will at least see warnings...maybe I should make that an error so it will fail any PRs that introduce this condition?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the bigger thing is that the check is happening twice in the same function. So the same code path is going to check the same check twice.

@NoelStephensUnity NoelStephensUnity enabled auto-merge (squash) March 24, 2025 23:21
{
if (NetworkManager.LogLevel <= LogLevel.Developer)
{
Debug.LogWarning($"[{nameof(NetworkSpawnManager)}][{nameof(ChangeOwnership)}] Attempting to change ownership to Client-{clientId} when the owner is already {networkObject.OwnerClientId}! (Ignoring)");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the bigger thing is that the check is happening twice in the same function. So the same code path is going to check the same check twice.

@NoelStephensUnity NoelStephensUnity merged commit c754a2c into develop-2.0.0 Mar 25, 2025
27 checks passed
@NoelStephensUnity NoelStephensUnity deleted the fix/da-change-ownership-results-in-invalid-previous-and-current-clientids branch March 25, 2025 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect value for ulong previous in OnOwnershipChanged on owner side, triggering issue in NetworkTransform
3 participants