Skip to content

Commit 1f3c7a7

Browse files
update - child network behaviours
This update is the first pass to making ChildNetworkBehaviours a table keyed off of the NetworkBehahviour identifiers. This allows for the removal of a NetworkBehaviour without it impacting the remaining NetworkBehaviours. This could most likely be optimized by generating the initial table ahead of time on each prefab. In-scene placed that are not registered prefabs would need to do this upon being instantiated.
1 parent 6cf0413 commit 1f3c7a7

5 files changed

Lines changed: 134 additions & 85 deletions

File tree

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ internal void ProcessDirtyObjectServer(NetworkObject dirtyObj, bool forceSend)
5656
if (m_NetworkManager.DistributedAuthorityMode || dirtyObj.IsNetworkVisibleTo(client.ClientId))
5757
{
5858
// Sync just the variables for just the objects this client sees
59-
for (int k = 0; k < dirtyObj.ChildNetworkBehaviours.Count; k++)
59+
foreach(var childBehaviour in dirtyObj.ChildNetworkBehaviours)
6060
{
61-
dirtyObj.ChildNetworkBehaviours[k].NetworkVariableUpdate(client.ClientId, forceSend);
61+
childBehaviour.Value.NetworkVariableUpdate(client.ClientId, forceSend);
6262
}
6363
}
6464
}
@@ -73,9 +73,9 @@ internal void ProcessDirtyObjectServer(NetworkObject dirtyObj, bool forceSend)
7373
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7474
internal void ProcessDirtyObjectClient(NetworkObject dirtyObj, bool forceSend)
7575
{
76-
for (int k = 0; k < dirtyObj.ChildNetworkBehaviours.Count; k++)
76+
foreach (var childBehaviour in dirtyObj.ChildNetworkBehaviours)
7777
{
78-
dirtyObj.ChildNetworkBehaviours[k].NetworkVariableUpdate(NetworkManager.ServerClientId, forceSend);
78+
childBehaviour.Value.NetworkVariableUpdate(NetworkManager.ServerClientId, forceSend);
7979
}
8080
}
8181

@@ -86,9 +86,9 @@ internal void ProcessDirtyObjectClient(NetworkObject dirtyObj, bool forceSend)
8686
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8787
internal void PostProcessDirtyObject(NetworkObject dirtyObj)
8888
{
89-
for (int k = 0; k < dirtyObj.ChildNetworkBehaviours.Count; k++)
89+
foreach (var behaviourEntry in dirtyObj.ChildNetworkBehaviours)
9090
{
91-
var behaviour = dirtyObj.ChildNetworkBehaviours[k];
91+
var behaviour = behaviourEntry.Value;
9292
for (int i = 0; i < behaviour.NetworkVariableFields.Count; i++)
9393
{
9494
// Set to true for NetworkVariable to ignore duplication of the
@@ -116,7 +116,7 @@ internal void ResetDirtyObject(NetworkObject dirtyObj, bool forceSend)
116116
{
117117
foreach (var behaviour in dirtyObj.ChildNetworkBehaviours)
118118
{
119-
behaviour.PostNetworkVariableWrite(forceSend);
119+
behaviour.Value.PostNetworkVariableWrite(forceSend);
120120
}
121121
}
122122

@@ -164,9 +164,9 @@ internal void ProcessDirtyObject(NetworkObject networkObject, bool forceSend)
164164
}
165165

166166
// Pre-variable update
167-
for (int k = 0; k < networkObject.ChildNetworkBehaviours.Count; k++)
167+
foreach (var childBehaviour in networkObject.ChildNetworkBehaviours)
168168
{
169-
networkObject.ChildNetworkBehaviours[k].PreVariableUpdate();
169+
childBehaviour.Value.PreVariableUpdate();
170170
}
171171

172172
// Server sends updates to all clients where a client sends updates

0 commit comments

Comments
 (0)