Skip to content

Commit b414c7e

Browse files
author
Unity Technologies
committed
## [1.0.12] - 2023-06-19 ### Changed * Updated com.unity.entities dependency to 1.0.11 ### Fixed * `MultiplayerPlayModeWindow > Dump Packet Logs` now works more reliably, now works with NUnit tests, and dump files are named with more context. * Fixed bug in `GhostSendSystem` that caused it to not replicate ghosts when enabling packet dumps. `GhostValuesAreSerialized_WithPacketDumpsEnabled` test added.
1 parent 1467245 commit b414c7e

18 files changed

+143
-175
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
4+
## [1.0.12] - 2023-06-19
5+
6+
### Changed
7+
* Updated com.unity.entities dependency to 1.0.11
8+
9+
### Fixed
10+
* `MultiplayerPlayModeWindow > Dump Packet Logs` now works more reliably, now works with NUnit tests, and dump files are named with more context.
11+
* Fixed bug in `GhostSendSystem` that caused it to not replicate ghosts when enabling packet dumps. `GhostValuesAreSerialized_WithPacketDumpsEnabled` test added.
12+
13+
314
## [1.0.11] - 2023-06-02
415

516
### Fixed

Editor/MultiplayerPlayModeWindow.cs

-72
Original file line numberDiff line numberDiff line change
@@ -1267,78 +1267,6 @@ protected override void OnUpdate()
12671267
}
12681268
}
12691269

1270-
1271-
/// <summary>
1272-
/// System that sync enable/disable packet dump for the <see cref="NetworkStreamConnection"/> based on the
1273-
/// playmode tool setting.
1274-
/// </summary>
1275-
[RequireMatchingQueriesForUpdate]
1276-
[UpdateInGroup(typeof(GhostSimulationSystemGroup))]
1277-
internal partial class MultiplayerPlaymodeLoggingSystem : SystemBase
1278-
{
1279-
public bool ShouldDumpPackets { get; set; }
1280-
public bool IsDumpingPackets { get; private set; }
1281-
1282-
private BeginSimulationEntityCommandBufferSystem m_CmdBuffer;
1283-
EntityQuery m_logQuery;
1284-
1285-
protected override void OnCreate()
1286-
{
1287-
ShouldDumpPackets = false;
1288-
IsDumpingPackets = false;
1289-
m_CmdBuffer = World.GetOrCreateSystemManaged<BeginSimulationEntityCommandBufferSystem>();
1290-
m_logQuery = EntityManager.CreateEntityQuery(ComponentType.ReadOnly<EnablePacketLogging>());
1291-
}
1292-
1293-
protected override void OnUpdate()
1294-
{
1295-
if (World.IsThinClient())
1296-
return;
1297-
1298-
if (SystemAPI.TryGetSingleton<NetCodeDebugConfig>(out var cfg))
1299-
{
1300-
if (ShouldDumpPackets != IsDumpingPackets)
1301-
{
1302-
cfg.DumpPackets = ShouldDumpPackets;
1303-
SystemAPI.SetSingleton(cfg);
1304-
}
1305-
else
1306-
ShouldDumpPackets = cfg.DumpPackets;
1307-
IsDumpingPackets = cfg.DumpPackets;
1308-
}
1309-
else
1310-
{
1311-
if (ShouldDumpPackets != IsDumpingPackets)
1312-
{
1313-
if (ShouldDumpPackets)
1314-
{
1315-
var cmdBuffer = m_CmdBuffer.CreateCommandBuffer();
1316-
Entities.WithNone<EnablePacketLogging>()
1317-
.ForEach((Entity entity, in NetworkStreamConnection conn) =>
1318-
{
1319-
cmdBuffer.AddComponent<EnablePacketLogging>(entity);
1320-
}).Schedule();
1321-
}
1322-
else
1323-
{
1324-
var cmdBuffer = m_CmdBuffer.CreateCommandBuffer();
1325-
Entities.WithAll<EnablePacketLogging>().ForEach((Entity entity, in NetworkStreamConnection conn) =>
1326-
{
1327-
cmdBuffer.RemoveComponent<EnablePacketLogging>(entity);
1328-
}).Schedule();
1329-
}
1330-
m_CmdBuffer.AddJobHandleForProducer(Dependency);
1331-
IsDumpingPackets = ShouldDumpPackets;
1332-
}
1333-
else
1334-
{
1335-
IsDumpingPackets = m_logQuery.CalculateEntityCount()>0;
1336-
ShouldDumpPackets = IsDumpingPackets;
1337-
}
1338-
}
1339-
}
1340-
}
1341-
13421270
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation | WorldSystemFilterFlags.Editor)]
13431271
[CreateAfter(typeof(SceneSystem))]
13441272
internal partial struct ConfigureClientGUIDSystem : ISystem

Runtime/Connection/WarnAboutStaleRpcSystem.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public void Execute(Entity entity, ref ReceiveRpcCommandRequest command)
2929
{
3030
if (!command.IsConsumed && ++command.Age >= netDebug.MaxRpcAgeFrames)
3131
{
32-
var warning = (FixedString512Bytes)FixedString.Format("In '{0}', NetCode RPC {1} has not been consumed or destroyed for '{2}' (MaxRpcAgeFrames) frames!", worldName, entity.ToFixedString(), command.Age);
33-
warning.Append((FixedString128Bytes)" Assumed unhandled. Call .Consume(), or remove the RPC component, or destroy the entity.");
32+
var warning = (FixedString512Bytes) $"[{worldName}] NetCode RPC {entity.ToFixedString()} has not been consumed or destroyed for '{command.Age}' (MaxRpcAgeFrames) frames! Assumed unhandled. Either a) call .Consume(), or b) remove the ReceiveRpcCommandRequestComponent component, or c) destroy the entity.";
3433
netDebug.LogWarning(warning);
3534

3635
command.Consume();

Runtime/Debug/NetCodeDebugConfig.cs

+18-11
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,47 @@ public struct NetCodeDebugConfig : IComponentData
2929
/// When the <see cref="NetCodeDebugConfig.DumpPackets"/> is set to true, a <see cref="EnablePacketLogging"/> component is added to all connection.
3030
/// </summary>
3131
[BurstCompile]
32+
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ServerSimulation)]
3233
[UpdateInGroup(typeof(GhostSimulationSystemGroup))]
3334
internal partial struct DebugConnections : ISystem
3435
{
3536
EntityQuery m_ConnectionsQueryWithout;
3637
EntityQuery m_ConnectionsQueryWith;
3738

39+
public bool EditorApplyLoggerSettings;
40+
public NetCodeDebugConfig ForceSettings;
41+
3842
[BurstCompile]
3943
public void OnCreate(ref SystemState state)
4044
{
4145
m_ConnectionsQueryWithout = state.EntityManager.CreateEntityQuery(new EntityQueryBuilder(Allocator.Temp).WithAll<NetworkStreamConnection>().WithNone<EnablePacketLogging>());
4246
m_ConnectionsQueryWith = state.EntityManager.CreateEntityQuery(new EntityQueryBuilder(Allocator.Temp).WithAll<NetworkStreamConnection>().WithAll<EnablePacketLogging>());
43-
state.RequireForUpdate<NetCodeDebugConfig>();
4447
}
4548

4649
public void OnUpdate(ref SystemState state)
4750
{
48-
if (state.WorldUnmanaged.IsThinClient())
49-
return;
50-
51-
var debugConfig = SystemAPI.GetSingleton<NetCodeDebugConfig>();
52-
var targetLogLevel = debugConfig.LogLevel;
53-
var shouldDumpPackets = debugConfig.DumpPackets;
51+
var netDbg = SystemAPI.GetSingletonRW<NetDebug>();
52+
if (!SystemAPI.TryGetSingleton<NetCodeDebugConfig>(out var debugConfig))
53+
{
54+
// No user-defined config, so take the NetDebug defaults:
55+
debugConfig.LogLevel = netDbg.ValueRO.LogLevel;
56+
debugConfig.DumpPackets = false;
57+
}
5458

5559
#if UNITY_EDITOR
5660
if (MultiplayerPlayModePreferences.ApplyLoggerSettings)
5761
{
58-
targetLogLevel = MultiplayerPlayModePreferences.TargetLogLevel;
59-
shouldDumpPackets = MultiplayerPlayModePreferences.TargetShouldDumpPackets;
62+
debugConfig.LogLevel = MultiplayerPlayModePreferences.TargetLogLevel;
63+
debugConfig.DumpPackets = MultiplayerPlayModePreferences.TargetShouldDumpPackets;
6064
}
6165
#endif
6266

63-
SystemAPI.GetSingletonRW<NetDebug>().ValueRW.LogLevel = targetLogLevel;
67+
if (netDbg.ValueRO.LogLevel != debugConfig.LogLevel)
68+
{
69+
netDbg.ValueRW.LogLevel = debugConfig.LogLevel;
70+
}
6471

65-
if (shouldDumpPackets)
72+
if (debugConfig.DumpPackets)
6673
{
6774
state.EntityManager.AddComponent<EnablePacketLogging>(m_ConnectionsQueryWithout);
6875
}

Runtime/Debug/NetDebug.cs

+8-12
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void Init(ref FixedString512Bytes logFolder, ref FixedString128Bytes worl
186186
m_NetDebugPacketLoggerHandle = new LoggerConfig()
187187
.OutputTemplate("{Message}")
188188
.MinimumLevel.Set(LogLevel.Verbose)
189-
.WriteTo.File($"{logFolder}/NetcodePackets-New-{worldName}-{connectionId}.log")
189+
.WriteTo.File($"{logFolder}/NetcodePacket-{worldName}-{connectionId}.log")
190190
.CreateLogger(parameters).Handle;
191191
}
192192

@@ -489,22 +489,18 @@ internal static FixedString64Bytes PrintMask(uint mask)
489489
/// <summary>
490490
/// Method that print a human readable error message when the version protocol mismatch.
491491
/// </summary>
492-
/// <param name="netDebug"></param>
493-
/// <param name="debugPrefix"></param>
492+
/// <param name="error"></param>
494493
/// <param name="protocolVersion"></param>
495-
internal static void PrintProtocolVersionError(NetDebug netDebug, FixedString64Bytes debugPrefix, NetworkProtocolVersion protocolVersion)
494+
internal static void AppendProtocolVersionError(ref FixedString512Bytes error, NetworkProtocolVersion protocolVersion)
496495
{
497-
FixedString512Bytes debugLog = default;
498-
debugLog.Append(debugPrefix);
499-
debugLog.Append(FixedString.Format("NetCode={0} Game={1}", protocolVersion.NetCodeVersion,
496+
error.Append(FixedString.Format("NetCode={0} Game={1}", protocolVersion.NetCodeVersion,
500497
protocolVersion.GameVersion));
501498
FixedString32Bytes msg = " RpcCollection=";
502-
debugLog.Append(msg);
503-
debugLog.Append(protocolVersion.RpcCollectionVersion);
499+
error.Append(msg);
500+
error.Append(protocolVersion.RpcCollectionVersion);
504501
msg = " ComponentCollection=";
505-
debugLog.Append(msg);
506-
debugLog.Append(protocolVersion.ComponentCollectionVersion);
507-
netDebug.LogError(debugLog);
502+
error.Append(msg);
503+
error.Append(protocolVersion.ComponentCollectionVersion);
508504
}
509505

510506
/// <summary>

Runtime/Debug/NetDebugSystem.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ private void CreateNetDebugSingleton(EntityManager entityManager)
3636
var netDebug = new NetDebug();
3737
netDebug.Initialize();
3838

39+
#if UNITY_EDITOR
40+
if (MultiplayerPlayModePreferences.ApplyLoggerSettings)
41+
netDebug.LogLevel = MultiplayerPlayModePreferences.TargetLogLevel;
42+
#endif
43+
3944
#if NETCODE_DEBUG
4045
m_ComponentTypeNameLookupData = new NativeParallelHashMap<int, FixedString128Bytes>(1024, Allocator.Persistent);
4146
netDebug.ComponentTypeNameLookup = m_ComponentTypeNameLookupData.AsReadOnly();
@@ -57,11 +62,6 @@ public void OnCreate(ref SystemState state)
5762
ComponentType.ReadOnly<Prefab>(),
5863
ComponentType.ReadOnly<GhostPrefabMetaData>(),
5964
ComponentType.Exclude<PrefabDebugName>());
60-
61-
#if UNITY_EDITOR
62-
if (MultiplayerPlayModePreferences.ApplyLoggerSettings)
63-
m_NetDebugQuery.GetSingletonRW<NetDebug>().ValueRW.LogLevel = MultiplayerPlayModePreferences.TargetLogLevel;
64-
#endif
6565
#endif
6666
}
6767

Runtime/Rpc/RpcCollection.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,10 @@ public void RegisterRpc(ComponentType type, PortableFunctionPointer<RpcExecutor.
8888
{
8989
#if ENABLE_UNITY_COLLECTIONS_CHECKS
9090
if (rpcData.RpcType == type)
91-
throw new InvalidOperationException(
92-
String.Format("Registering RPC {0} multiple times is not allowed", type.GetManagedType()));
93-
throw new InvalidOperationException(
94-
String.Format("Type hash collision between types {0} and {1}", type.GetManagedType(), rpcData.RpcType.GetManagedType()));
91+
throw new InvalidOperationException($"Registering RPC {type.ToFixedString()} multiple times is not allowed! Existing: {rpcData.RpcType.ToFixedString()}!");
92+
throw new InvalidOperationException($"StableTypeHash collision between types {type.ToFixedString()} and {rpcData.RpcType.ToFixedString()} while registering RPC!");
9593
#else
96-
throw new InvalidOperationException(
97-
String.Format("Hash collision or multiple registrations for {0}", type.GetManagedType()));
94+
throw new InvalidOperationException($"Hash collision or multiple registrations for {type.ToFixedString()} while registering RPC! Existing: {rpcData.TypeHash}!");
9895
#endif
9996
}
10097

Runtime/Rpc/RpcSystem.cs

+11-9
Original file line numberDiff line numberDiff line change
@@ -537,25 +537,27 @@ public void Execute(Entity entity, in RpcSystem.ProtocolVersionError rpcError)
537537
{ Reason = NetworkStreamDisconnectReason.InvalidRpc });
538538
connection = connections[rpcError.connection].Value.ToFixedString();
539539
}
540-
netDebug.LogError(FixedString.Format("[{0}] RpcSystem received bad protocol version from {1}", worldName, connection));
541-
FixedString64Bytes prefix = "Local protocol: ";
542-
NetDebug.PrintProtocolVersionError(netDebug, prefix, localProtocol);
543-
prefix = "Remote protocol: ";
544-
NetDebug.PrintProtocolVersionError(netDebug, prefix, rpcError.remoteProtocol);
545540

546-
var s = (FixedString512Bytes)"RPC List: ";
541+
var errorHeader = (FixedString512Bytes)$"[{worldName}] RpcSystem received bad protocol version from {connection}";
542+
errorHeader.Append((FixedString32Bytes)"\nLocal protocol: ");
543+
NetDebug.AppendProtocolVersionError(ref errorHeader, localProtocol);
544+
errorHeader.Append((FixedString32Bytes)"\nRemote protocol: ");
545+
NetDebug.AppendProtocolVersionError(ref errorHeader, rpcError.remoteProtocol);
546+
netDebug.LogError(errorHeader);
547+
548+
var s = (FixedString512Bytes)"RPC List (for above 'bad protocol version' error): ";
547549
s.Append(rpcs.Length);
548550
netDebug.LogError(s);
549551

550552
for (int i = 0; i < rpcs.Length; ++i)
551-
netDebug.LogError(rpcs[i]);
553+
netDebug.LogError($"RpcHash[{i}] = {rpcs[i]}");
552554

553-
s = (FixedString512Bytes)"Component serializer data: ";
555+
s = (FixedString512Bytes)"Component serializer data (for above 'bad protocol version' error): ";
554556
s.Append(componentInfo.Length);
555557
netDebug.LogError(s);
556558

557559
for (int i = 0; i < componentInfo.Length; ++i)
558-
netDebug.LogError(componentInfo[i]);
560+
netDebug.LogError($"ComponentHash[{i}] = {componentInfo[i]}");
559561

560562
commandBuffer.DestroyEntity(entity);
561563
}

Runtime/Snapshot/GhostComponent.cs

+9
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ public static implicit operator SpawnedGhost(in GhostInstance comp)
9494
{
9595
return new SpawnedGhost(comp.ghostId, comp.spawnTick);
9696
}
97+
98+
/// <summary>
99+
/// Returns a human-readable GhostComponent FixedString, containing its values.
100+
/// </summary>
101+
/// <returns>A human-readable GhostComponent FixedString, containing its values.</returns>
102+
public FixedString128Bytes ToFixedString()
103+
{
104+
return $"GhostComponent[type:{ghostType}|id:{ghostId},st:{spawnTick.ToFixedString()}]";
105+
}
97106
}
98107

99108
/// <summary>

Runtime/Snapshot/GhostComponentSerializerCollectionSystemGroup.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public void AddSerializer(GhostComponentSerializer.State state)
330330
/// <param name="context">The context of this call, to aid in error reporting.</param>
331331
/// <exception cref="InvalidOperationException">Throws if user-code queries too early.</exception>
332332
[Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
333-
public void ThrowIfNotInRegistrationPhase(FixedString128Bytes context)
333+
public void ThrowIfNotInRegistrationPhase(in FixedString512Bytes context)
334334
{
335335
#if ENABLE_UNITY_COLLECTIONS_CHECKS
336336
if(!CollectionFinalized.IsCreated)
@@ -348,7 +348,7 @@ public void ThrowIfNotInRegistrationPhase(FixedString128Bytes context)
348348
/// <param name="context">The context of this call, to aid in error reporting.</param>
349349
/// <exception cref="InvalidOperationException">Throws if user-code queries too early.</exception>
350350
[Conditional("ENABLE_UNITY_COLLECTIONS_CHECKS")]
351-
public void ThrowIfCollectionNotFinalized(FixedString512Bytes context)
351+
public void ThrowIfCollectionNotFinalized(in FixedString512Bytes context)
352352
{
353353
#if ENABLE_UNITY_COLLECTIONS_CHECKS
354354
if (!CollectionFinalized.IsCreated || CollectionFinalized.Value == 0)

Runtime/Snapshot/GhostSendSystem.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1589,10 +1589,12 @@ public void OnUpdate(ref SystemState state)
15891589

15901590
foreach (var packet in SystemAPI.Query<AspectPacket>())
15911591
{
1592-
if (!m_ConnectionStateLookup.ContainsKey(packet.Entity)) { return; }
1592+
if (!m_ConnectionStateLookup.ContainsKey(packet.Entity))
1593+
continue;
15931594

15941595
var conState = m_ConnectionStates[m_ConnectionStateLookup[packet.Entity]];
1595-
if (conState.NetDebugPacket.IsCreated) { return; }
1596+
if (conState.NetDebugPacket.IsCreated)
1597+
continue;
15961598

15971599
NetDebugInterop.InitDebugPacketIfNotCreated(ref conState.NetDebugPacket, ref m_LogFolder, ref worldNameFixed, packet.Id.ValueRO.Value);
15981600

0 commit comments

Comments
 (0)