Skip to content

Commit e57855b

Browse files
quantum-shubhamEmandM
authored andcommitted
fix: keep NetworkObject queued when NetworkShow cannot flush throttled updates
ForceSendIfDirtyOnNetworkShow removed the NetworkObject from the updater even when NetworkVariableUpdateTraits held back its dirty variables, so those changes were not sent until the variable was modified again. Re-queue the object when anything is still dirty after the forced flush, and add a regression test for showing an object while NetworkList updates are throttled.
1 parent cc39600 commit e57855b

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

‎com.unity.netcode.gameobjects/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2323
### Fixed
2424

2525
- Issue where a client synchronized while a `NetworkList<T>` still had unsent changes applied those changes twice, resulting in duplicate entries and index-based events landing on the wrong elements on that client. (#4215)
26+
- Issue where showing a `NetworkObject` with `NetworkShow` while its `NetworkVariable` updates were held back by `NetworkVariableUpdateTraits` stopped those pending changes from being sent until the variable was modified again. (#4215)
2627
- Issue where moving a `NetworkObject` into another scene made the clients that did not observe it log "Trying to synchronize NetworkObjectId but it was not spawned". The scene migration is now only sent to the clients that observe the `NetworkObject`. (#4185)
2728
- Issue where a `NetworkObject` that was moved into another scene while hidden from a client spawned in that client's active scene when it was shown with `NetworkShow`, instead of the scene it is in on the server. (#4185)
2829
- Issue where mixed authority nested `NetworkTransform` instances could stop child/nested instances from updating because an authoritative `NetworkTransform` (root or otherwise) would remove the `NetworkObject` from the update group, preventing non-authoritative instances from updating their state on the authority side. (#4169)

‎com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviourUpdater.cs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,19 @@ internal void ForceSendIfDirtyOnNetworkShow(NetworkObject networkObject)
138138
// Remove it from the pending and queued dirty objects lists
139139
m_PendingDirtyNetworkObjects.Remove(networkObject);
140140
m_DirtyNetworkObjects.Remove(networkObject);
141+
142+
// Anything still dirty was held back by its update traits, keep it queued so a later tick sends it
143+
foreach (var behaviour in networkObject.ChildNetworkBehaviours.Values)
144+
{
145+
foreach (var networkVariable in behaviour.NetworkVariableFields)
146+
{
147+
if (networkVariable.IsDirty())
148+
{
149+
AddForUpdate(networkObject);
150+
return;
151+
}
152+
}
153+
}
141154
}
142155

143156
/// <summary>

‎com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariable/NetworkListTests.cs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,45 @@ public IEnumerator LateJoinWithPendingChanges()
126126
AssertOnTimeout("Late joined client did not match the authority's list");
127127
}
128128

129+
/// <summary>
130+
/// Validates that showing an object while list updates are held back by update traits
131+
/// still delivers the pending changes once they can be sent.
132+
/// </summary>
133+
[UnityTest]
134+
public IEnumerator NetworkShowWithThrottledPendingChanges()
135+
{
136+
var authority = GetAuthorityNetworkManager();
137+
var nonAuthority = GetNonAuthorityNetworkManager();
138+
var instantiatedObject = SpawnObject(m_ListObjectPrefab, authority).GetComponent<NetworkObject>();
139+
m_TestObjectId = instantiatedObject.NetworkObjectId;
140+
141+
yield return WaitForSpawnedOnAllOrTimeOut(instantiatedObject);
142+
AssertOnTimeout("[Setup] Failed to spawn list object");
143+
144+
instantiatedObject.NetworkHide(nonAuthority.LocalClientId);
145+
yield return WaitForConditionOrTimeOut(() => !nonAuthority.SpawnManager.SpawnedObjects.ContainsKey(m_TestObjectId));
146+
AssertOnTimeout("[Setup] Failed to hide list object");
147+
148+
// Hold back deltas so these changes are still pending when the object is shown
149+
var list = instantiatedObject.GetComponent<NetworkListTest>().TheList;
150+
list.SetUpdateTraits(new NetworkVariableUpdateTraits { MinSecondsBetweenUpdates = 3600 });
151+
m_ExpectedValues.Clear();
152+
for (int i = 0; i < 5; i++)
153+
{
154+
m_ExpectedValues.Add(i);
155+
list.Add(i);
156+
}
157+
158+
instantiatedObject.NetworkShow(nonAuthority.LocalClientId);
159+
yield return WaitForConditionOrTimeOut(() => nonAuthority.SpawnManager.SpawnedObjects.ContainsKey(m_TestObjectId));
160+
AssertOnTimeout("[Setup] Failed to show list object");
161+
Assert.IsTrue(list.IsDirty(), "[Setup] Changes should still be pending after the object was shown");
162+
163+
list.SetUpdateTraits(default);
164+
yield return WaitForConditionOrTimeOut(OnVerifyData);
165+
AssertOnTimeout("Clients did not receive the changes that were pending when the object was shown");
166+
}
167+
129168
[UnityTest]
130169
public IEnumerator ValidateNetworkListSynchronization()
131170
{

0 commit comments

Comments
 (0)