-
Notifications
You must be signed in to change notification settings - Fork 464
fix: mixed authority nested NetworkTransform stops updating non-authority nested NetworkTransforms #4169
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
Open
NoelStephensUnity
wants to merge
12
commits into
develop-2.0.0
Choose a base branch
from
fix/mixed-authority-nested-transform-updates
base: develop-2.0.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+242
−52
Open
fix: mixed authority nested NetworkTransform stops updating non-authority nested NetworkTransforms #4169
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6b2f648
fix
NoelStephensUnity e98ed18
test
NoelStephensUnity ff196a3
update
NoelStephensUnity bef6418
style
NoelStephensUnity 1bef954
fix
NoelStephensUnity 8920574
test
NoelStephensUnity 674b7d2
update
NoelStephensUnity fd5b4f0
Merge branch 'develop-2.0.0' into fix/mixed-authority-nested-transfor…
NoelStephensUnity 5791e63
test: collapse the mixed authority fixtures and add GetManagersInstance
NoelStephensUnity 80f9d01
Update com.unity.netcode.gameobjects/CHANGELOG.md
NoelStephensUnity d417f4f
update
NoelStephensUnity a7daf20
Merge branch 'fix/mixed-authority-nested-transform-updates' of https:…
NoelStephensUnity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 94 additions & 50 deletions
144
...netcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkTransformMixedAuthorityTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...tcode.gameobjects/Tests/Runtime/NetworkTransform/NetworkTransformMixedMotionModelTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #if COM_UNITY_MODULES_PHYSICS | ||
| using System.Collections; | ||
| using NUnit.Framework; | ||
| using Unity.Netcode.Components; | ||
| using Unity.Netcode.TestHelpers.Runtime; | ||
| using UnityEngine; | ||
| using UnityEngine.TestTools; | ||
|
|
||
| namespace Unity.Netcode.RuntimeTests | ||
| { | ||
| internal class NetworkTransformMixedMotionModelTests : NetcodeIntegrationTest | ||
| { | ||
| protected override int NumberOfClients => 2; | ||
|
|
||
| private GameObject m_MixedMotionModelPrefab; | ||
|
|
||
| protected override void OnServerAndClientsCreated() | ||
| { | ||
| m_MixedMotionModelPrefab = CreateNetworkObjectPrefab("MixedMotionModel"); | ||
|
|
||
| // The root is owner authoritative and driven by the rigidbody, which places it in the fixed update registration | ||
| var rootNetworkTransform = m_MixedMotionModelPrefab.AddComponent<NetworkTransform>(); | ||
| rootNetworkTransform.AuthorityMode = NetworkTransform.AuthorityModes.Owner; | ||
| var rigidbody = m_MixedMotionModelPrefab.AddComponent<Rigidbody>(); | ||
| rigidbody.useGravity = false; | ||
| rigidbody.detectCollisions = false; | ||
| m_MixedMotionModelPrefab.AddComponent<NetworkRigidbody>().UseRigidBodyForMotion = true; | ||
|
|
||
| // The nested child is server authoritative and driven by the transform, which places it in the update registration | ||
| var childGameObject = new GameObject(); | ||
| childGameObject.transform.parent = m_MixedMotionModelPrefab.transform; | ||
| var childNetworkTransform = childGameObject.AddComponent<NetworkTransform>(); | ||
| childNetworkTransform.AuthorityMode = NetworkTransform.AuthorityModes.Server; | ||
| childNetworkTransform.InLocalSpace = true; | ||
|
|
||
| base.OnServerAndClientsCreated(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A NetworkObject that mixes both the authority motion model and the rigidbody motion model has each nested | ||
| /// NetworkTransform registered under a different update. Gaining authority over the instance in one update | ||
| /// should not leave it registered for the other. | ||
| /// </summary> | ||
| [UnityTest] | ||
| public IEnumerator UpdateRegistrationFollowsMotionModel() | ||
| { | ||
| var instance = SpawnObject(m_MixedMotionModelPrefab, m_ServerNetworkManager).GetComponent<NetworkObject>(); | ||
| yield return WaitForSpawnedOnAllOrTimeOut(instance); | ||
| AssertOnTimeout($"Failed to spawn {instance.name} on all clients!"); | ||
|
|
||
| var newOwner = m_ClientNetworkManagers[0]; | ||
|
|
||
| // Establish the baseline before ownership is transferred, otherwise the check below would still pass if this instance was never registered for the fixed update to begin with. | ||
| Assert.True(newOwner.NetworkTransformFixedUpdate.ContainsKey(instance.NetworkObjectId), $"Client-{newOwner.LocalClientId} should initially be registered for the fixed update!"); | ||
|
|
||
| instance.ChangeOwnership(newOwner.LocalClientId); | ||
| yield return WaitForConditionOrTimeOut(() => newOwner.SpawnManager.SpawnedObjects[instance.NetworkObjectId].OwnerClientId == newOwner.LocalClientId); | ||
|
NoelStephensUnity marked this conversation as resolved.
|
||
| AssertOnTimeout($"Client-{newOwner.LocalClientId} never gained ownership of {instance.name}!"); | ||
|
|
||
| // The new owner is the authority for the rigidbody driven root, so nothing on this instance needs the fixed | ||
| // update any longer. The server authoritative child still needs the standard update. | ||
| Assert.False(newOwner.NetworkTransformFixedUpdate.ContainsKey(instance.NetworkObjectId), $"Client-{newOwner.LocalClientId} is still registered for the fixed update!"); | ||
| Assert.True(newOwner.NetworkTransformUpdate.ContainsKey(instance.NetworkObjectId), $"Client-{newOwner.LocalClientId} is not registered for the update!"); | ||
| } | ||
| } | ||
| } | ||
| #endif | ||
2 changes: 2 additions & 0 deletions
2
....gameobjects/Tests/Runtime/NetworkTransform/NetworkTransformMixedMotionModelTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.