Skip to content

Commit 9c61c51

Browse files
fix: Fix metrics reporting for Ownership Change, Spawn and Destroy bytes (#1233)
Co-authored-by: becksebenius-unity <[email protected]>
1 parent b07fe79 commit 9c61c51

22 files changed

+58
-125
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,12 @@ internal unsafe void __sendClientRpc(FastBufferWriter writer, uint rpcMethodId,
181181
{
182182
foreach (var client in NetworkManager.ConnectedClients)
183183
{
184-
var bytesReported = NetworkManager.LocalClientId == client.Key
185-
? 0
186-
: messageSize;
187184
NetworkManager.NetworkMetrics.TrackRpcSent(
188185
client.Key,
189186
NetworkObjectId,
190187
rpcMethodName,
191188
__getTypeName(),
192-
bytesReported);
189+
messageSize);
193190
}
194191
}
195192
#endif

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ private void Initialize(bool server)
536536
#if MULTIPLAYER_TOOLS
537537
NetworkSolutionInterface.SetInterface(new NetworkSolutionInterfaceParameters
538538
{
539-
NetworkObjectProvider = new NetworkObjectProvider(this)
539+
NetworkObjectProvider = new NetworkObjectProvider(this),
540540
});
541541
#endif
542542

@@ -893,6 +893,7 @@ public SocketTasks StartHost()
893893
var socketTasks = NetworkConfig.NetworkTransport.StartServer();
894894
m_MessagingSystem.ClientConnected(ServerClientId);
895895
LocalClientId = ServerClientId;
896+
NetworkMetrics.SetConnectionId(LocalClientId);
896897

897898
IsServer = true;
898899
IsClient = true;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,7 @@ public void NetworkHide(ulong clientId)
317317
};
318318
// Send destroy call
319319
var size = NetworkManager.SendMessage(message, NetworkDelivery.ReliableSequenced, clientId);
320-
var bytesReported = NetworkManager.LocalClientId == clientId
321-
? 0
322-
: size;
323-
NetworkManager.NetworkMetrics.TrackObjectDestroySent(clientId, NetworkObjectId, name, bytesReported);
320+
NetworkManager.NetworkMetrics.TrackObjectDestroySent(clientId, NetworkObjectId, name, size);
324321
}
325322
}
326323

com.unity.netcode.gameobjects/Runtime/Messaging/CustomMessageManager.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ internal void InvokeUnnamedMessage(ulong clientId, FastBufferReader reader)
4040
((UnnamedMessageDelegate)handler).Invoke(clientId, reader);
4141
}
4242
}
43-
var bytesReported = m_NetworkManager.LocalClientId == clientId
44-
? 0
45-
: reader.Length;
46-
m_NetworkManager.NetworkMetrics.TrackUnnamedMessageReceived(clientId, bytesReported);
43+
m_NetworkManager.NetworkMetrics.TrackUnnamedMessageReceived(clientId, reader.Length);
4744
}
4845

4946
/// <summary>
@@ -81,9 +78,6 @@ public void SendUnnamedMessage(ulong clientId, FastBufferWriter messageBuffer, N
8178
Data = messageBuffer
8279
};
8380
var size = m_NetworkManager.SendMessage(message, networkDelivery, clientId);
84-
var bytesReported = m_NetworkManager.LocalClientId == clientId
85-
? 0
86-
: size;
8781
m_NetworkManager.NetworkMetrics.TrackUnnamedMessageSent(clientId, size);
8882
}
8983

@@ -199,9 +193,6 @@ public void SendNamedMessage(string messageName, ulong clientId, FastBufferWrite
199193
Data = messageStream
200194
};
201195
var size = m_NetworkManager.SendMessage(message, networkDelivery, clientId);
202-
var bytesReported = m_NetworkManager.LocalClientId == clientId
203-
? 0
204-
: size;
205196
m_NetworkManager.NetworkMetrics.TrackNamedMessageSent(clientId, messageName, size);
206197
}
207198

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ChangeOwnershipMessage.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ public void Handle(ulong senderId, NetworkManager networkManager, int messageSiz
4747
networkObject.InvokeBehaviourOnGainedOwnership();
4848
}
4949

50-
var bytesReported = networkManager.LocalClientId == senderId
51-
? 0
52-
: messageSize;
53-
networkManager.NetworkMetrics.TrackOwnershipChangeReceived(senderId, networkObject.NetworkObjectId, networkObject.name, bytesReported);
50+
networkManager.NetworkMetrics.TrackOwnershipChangeReceived(senderId, networkObject.NetworkObjectId, networkObject.name, messageSize);
5451
}
5552
}
5653
}

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ConnectionApprovedMessage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static void Receive(FastBufferReader reader, in NetworkContext context)
6262
public void Handle(FastBufferReader reader, ulong clientId, NetworkManager networkManager)
6363
{
6464
networkManager.LocalClientId = OwnerClientId;
65+
networkManager.NetworkMetrics.SetConnectionId(networkManager.LocalClientId);
6566

6667
var time = new NetworkTime(networkManager.NetworkTickSystem.TickRate, NetworkTick);
6768
networkManager.NetworkTimeSystem.Reset(time.Time, 0.15f); // Start with a constant RTT of 150 until we receive values from the transport.

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/CreateObjectMessage.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ public static void Receive(FastBufferReader reader, in NetworkContext context)
2424
public void Handle(ulong senderId, FastBufferReader reader, NetworkManager networkManager)
2525
{
2626
var networkObject = NetworkObject.AddSceneObject(ObjectInfo, reader, networkManager);
27-
var bytesReported = networkManager.LocalClientId == senderId
28-
? 0
29-
: reader.Length;
30-
networkManager.NetworkMetrics.TrackObjectSpawnReceived(senderId, networkObject.NetworkObjectId, networkObject.name, bytesReported);
27+
networkManager.NetworkMetrics.TrackObjectSpawnReceived(senderId, networkObject.NetworkObjectId, networkObject.name, reader.Length);
3128
}
3229
}
3330
}

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/DestroyObjectMessage.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ public void Handle(ulong senderId, NetworkManager networkManager, int messageSiz
3434
return;
3535
}
3636

37-
var bytesReported = networkManager.LocalClientId == senderId
38-
? 0
39-
: messageSize;
40-
networkManager.NetworkMetrics.TrackObjectDestroyReceived(senderId, NetworkObjectId, networkObject.name, bytesReported);
37+
networkManager.NetworkMetrics.TrackObjectDestroyReceived(senderId, NetworkObjectId, networkObject.name, messageSize);
4138
networkManager.SpawnManager.OnDespawnObject(networkObject, true);
4239
}
4340
}

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,13 @@ public void Serialize(FastBufferWriter writer)
8383
NetworkBehaviour.NetworkVariableIndexesToReset.Add(k);
8484
}
8585

86-
var bytesReported = NetworkBehaviour.NetworkManager.LocalClientId == ClientId
87-
? 0
88-
: writer.Length;
8986
NetworkBehaviour.NetworkManager.NetworkMetrics.TrackNetworkVariableDeltaSent(
9087
ClientId,
9188
NetworkBehaviour.NetworkObjectId,
9289
NetworkBehaviour.name,
9390
NetworkBehaviour.NetworkVariableFields[k].Name,
9491
NetworkBehaviour.__getTypeName(),
95-
bytesReported);
92+
writer.Length);
9693
}
9794
}
9895
}
@@ -183,16 +180,14 @@ public void Handle(ulong senderId, FastBufferReader reader, NetworkManager netwo
183180
int readStartPos = reader.Position;
184181

185182
behaviour.NetworkVariableFields[i].ReadDelta(reader, networkManager.IsServer);
186-
var bytesReported = networkManager.LocalClientId == senderId
187-
? 0
188-
: reader.Length;
183+
189184
networkManager.NetworkMetrics.TrackNetworkVariableDeltaReceived(
190185
senderId,
191186
behaviour.NetworkObjectId,
192187
behaviour.name,
193188
behaviour.NetworkVariableFields[i].Name,
194189
behaviour.__getTypeName(),
195-
bytesReported);
190+
reader.Length);
196191

197192

198193
if (networkManager.NetworkConfig.EnsureNetworkVariableLengthSafety)

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ServerLogMessage.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ public static void Receive(FastBufferReader reader, in NetworkContext context)
3131

3232
public void Handle(ulong senderId, NetworkManager networkManager, int messageSize)
3333
{
34-
var bytesReported = networkManager.LocalClientId == senderId
35-
? 0
36-
: messageSize;
37-
networkManager.NetworkMetrics.TrackServerLogReceived(senderId, (uint)LogType, bytesReported);
34+
networkManager.NetworkMetrics.TrackServerLogReceived(senderId, (uint)LogType, messageSize);
3835

3936
switch (LogType)
4037
{

0 commit comments

Comments
 (0)