Skip to content

Commit a002b98

Browse files
chore: asmdef guid references (#4152)
* chore: reference the Netcode for Entities assemblies by GUID Three asmdefs named "Unity.NetCode" and "Unity.NetCode.Editor" as strings. Unity silently drops an asmdef reference it cannot resolve, so renaming either assembly would make every UNIFIED_NETCODE code path fail to compile with nothing pointing at the cause. A GUID reference resolves to whichever asmdef asset carries that GUID regardless of the name inside it, which is how NGO's own editor assembly rename stayed transparent to projects referencing it. The GUIDs are read from the installed package's .asmdef.meta files, not derived: Unity.NetCode 953adc2a6b8b4e3c8df5b728bcd546e9 Unity.NetCode.Editor eb8cf780bf058694ebf7ec5cf5b8cfa3 Unity.Entities is left by name. It is not the assembly at risk of a rename, and converting it would add surface that cannot be checked here for no benefit. Not verified locally: confirming a GUID reference resolves needs an editor with both packages installed. Worth an import in a project that has Netcode for Entities before this is relied on - if a GUID is wrong the reference drops silently, which is the failure this is meant to prevent. * chore: rename the internal NetworkMetrics to ToolsNetworkMetrics The last of the three type names NGO and Netcode for Entities share. This one is internal, so no user sees it and it is not a compile error either way: a source-declared type beats an imported one, so NGO's own assembly would take its own and warn CS0436. But once the two namespaces converge the warning appears in our build log for a name nobody can act on from outside, and "Unity.Netcode holds no name that collides" is a simpler thing to be able to say than "two of the three". ToolsNetworkMetrics keeps the suffix, so it still reads as a pair with its sibling NullNetworkMetrics - the two INetworkMetrics implementations, one behind MULTIPLAYER_TOOLS and one not. Five sites in two files: the declaration, both constructors, the profiler marker and the single construction site. Everything else that reads NetworkMetrics is a property of that name on NetworkManager, NetworkMetricsManager or NetworkTransport, all typed INetworkMetrics and untouched. The profiler marker keeps its old string rather than following the rename. It is what shows up in the Profiler, and an internal rename is not a reason to move it, so nameof gives way to the literal with a comment saying why. Verified as far as this machine allows: runtime, editor and runtime tests all compile clean, which covers the #else branch. The renamed class is entirely inside #if MULTIPLAYER_TOOLS and the harness has no Unity.Multiplayer.Tools references, so that branch cannot be built here. A parse pass over the file with the define on reports only CS0246/CS0234 for the tools types and no structural error, which is what a class and constructor disagreeing on a name would produce. The define-on path still wants a real editor build before this is trusted. --------- Co-authored-by: Michał Chrobot <124174716+michalChrobot@users.noreply.github.com>
1 parent 5d301b2 commit a002b98

6 files changed

Lines changed: 11 additions & 9 deletions

File tree

com.unity.netcode.gameobjects/Editor/Unity.Netcode.Editor.asmdef

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"Unity.Networking.Transport",
99
"Unity.Services.Core",
1010
"Unity.Services.Authentication",
11-
"Unity.NetCode",
12-
"Unity.NetCode.Editor"
11+
"GUID:953adc2a6b8b4e3c8df5b728bcd546e9",
12+
"GUID:eb8cf780bf058694ebf7ec5cf5b8cfa3"
1313
],
1414
"includePlatforms": [
1515
"Editor"

com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetricsManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void Initialize(NetworkManager networkManager)
2727
if (NetworkMetrics == null)
2828
{
2929
#if MULTIPLAYER_TOOLS
30-
NetworkMetrics = new NetworkMetrics();
30+
NetworkMetrics = new ToolsNetworkMetrics();
3131
#else
3232
NetworkMetrics = new NullNetworkMetrics();
3333
#endif

com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs renamed to com.unity.netcode.gameobjects/Runtime/Metrics/ToolsNetworkMetrics.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88

99
namespace Unity.Netcode
1010
{
11-
internal class NetworkMetrics : INetworkMetrics
11+
internal class ToolsNetworkMetrics : INetworkMetrics
1212
{
1313
private const ulong k_MaxMetricsPerFrame = 1000L;
1414
private static readonly Dictionary<uint, string> k_SceneEventTypeNames;
1515
private static readonly ProfilerMarker k_FrameDispatch;
1616

17-
static NetworkMetrics()
17+
static ToolsNetworkMetrics()
1818
{
1919
k_SceneEventTypeNames = new Dictionary<uint, string>();
2020
foreach (SceneEventType type in Enum.GetValues(typeof(SceneEventType)))
2121
{
2222
k_SceneEventTypeNames[(uint)type] = type.ToString();
2323
}
24-
k_FrameDispatch = new ProfilerMarker($"{nameof(NetworkMetrics)}.DispatchFrame");
24+
// Spelled out rather than nameof: this is the name shown in the Profiler, and it
25+
// should not move because the implementing type was renamed.
26+
k_FrameDispatch = new ProfilerMarker("NetworkMetrics.DispatchFrame");
2527
}
2628

2729
private static string GetSceneEventTypeName(uint typeCode)
@@ -85,7 +87,7 @@ private static string GetSceneEventTypeName(uint typeCode)
8587

8688
private ulong m_NumberOfMetricsThisFrame;
8789

88-
public NetworkMetrics()
90+
public ToolsNetworkMetrics()
8991
{
9092
Dispatcher = new MetricDispatcherBuilder()
9193
.WithCounters(m_TransportBytesSent, m_TransportBytesReceived)

com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs.meta renamed to com.unity.netcode.gameobjects/Runtime/Metrics/ToolsNetworkMetrics.cs.meta

File renamed without changes.

com.unity.netcode.gameobjects/Runtime/Unity.Netcode.Runtime.asmdef

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"Unity.Collections",
1515
"Unity.Burst",
1616
"Unity.Mathematics",
17-
"Unity.NetCode",
17+
"GUID:953adc2a6b8b4e3c8df5b728bcd546e9",
1818
"Unity.Entities"
1919
],
2020
"includePlatforms": [],

com.unity.netcode.gameobjects/Tests/Runtime/Unity.Netcode.Runtime.Tests.asmdef

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"Unity.Mathematics",
1515
"UnityEngine.TestRunner",
1616
"UnityEditor.TestRunner",
17-
"Unity.NetCode",
17+
"GUID:953adc2a6b8b4e3c8df5b728bcd546e9",
1818
"Unity.Entities"
1919
],
2020
"includePlatforms": [],

0 commit comments

Comments
 (0)