Skip to content

Commit 17d2cf1

Browse files
chore: n4e 7.0.0 spellings, review feedback and snapshot size
N4E 7.0.0 renamed NetCodeConfig to NetcodeConfig and moved its types into Unity.Netcode. Use the 7.0.0 spelling, aliased for 6.7.0 the way the rest of the unified code already is. The editor test assembly still declared UNIFIED_NETCODE as a versionDefine after #4158 made it project-level, so its unified block compiled while the runtime's did not. It also referenced Unity.NetCode by name alongside the GUID for the same assembly. Both removed, UNIFIED_NETCODE_7_0_0 added. The snapshot packet size drops from 15000 to 4096. A snapshot is sent unreliably, so losing any one of its fragments loses the whole snapshot: 4096 spans 3 datagrams at the 1400 byte MTU where 15000 spanned 11, and still caps ~840 ghosts at the measured 4.87 bytes each. The defaults version is bumped so a project that already recorded the marker picks the new value up. Review feedback: - The experimental opt-in is gone. N4E ships as a normal 3.0.0 release. - ResolveGlobalConfig's project scan is gone. N4E assigns NetcodeConfig.Global from an InitializeOnLoadMethod and delayCall runs after those complete, so there is nothing left for a scan to catch. - The apply log uses the contextual logger at Developer level. - UnifiedIsConfiguredCorrectly reports which setting is wrong rather than discarding the reason it already computed.
1 parent 2e3c48f commit 17d2cf1

7 files changed

Lines changed: 103 additions & 186 deletions

File tree

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,30 @@
11
#if UNIFIED_NETCODE
2-
using Unity.NetCode;
2+
using Unity.Netcode.Logging;
3+
#if !UNIFIED_NETCODE_7_0_0
4+
using NetcodeConfig = Unity.NetCode.NetCodeConfig;
5+
#endif
36
using UnityEditor;
4-
using UnityEngine;
57

68
namespace Unity.Netcode.GameObjects.Editor.Configuration
79
{
810
/// <summary>
9-
/// Writes the <see cref="NetCodeConfig"/> values NGO recommends for hybrid mode, once, the first time a
10-
/// <see cref="NetCodeConfig"/> is available.
11+
/// Writes the <see cref="NetcodeConfig"/> values NGO recommends for hybrid mode, once, the first time a
12+
/// <see cref="NetcodeConfig"/> is available.
1113
/// </summary>
1214
/// <remarks>
13-
/// This does not create <see cref="NetCodeConfig"/>. This finds the one N4E created and modifies it.
15+
/// This does not create <see cref="NetcodeConfig"/>. This finds the one N4E created and modifies it.
1416
/// Nothing tracks the project after that write. The defaults are inert in a project with no hybrid prefabs, and
1517
/// <see cref="NetworkManager"/> re-aligns the tick rate at start-up in a project that has them, so there is no
1618
/// reason to scan for ghost prefabs from the editor.
1719
/// </remarks>
1820
internal static class HybridNetcodeConfigApplier
1921
{
20-
/// <summary>
21-
/// Whether the user has to opt into the experimental unified netcode API before NGO writes anything.
22-
/// </summary>
23-
/// <remarks>
24-
/// TODO-RELEASE: Set this to true before the 6000.7.0 release manifest submission if Netcode for Entities
25-
/// ships the unified API as experimental and its scripting defines.
26-
/// Note: This is deliberately not a const: IDE0035 (remove unreachable code) is an error in this repository, so a
27-
/// const would fail the standards job as soon as it was set to false.
28-
/// </remarks>
29-
internal static readonly bool RequiresExperimentalOptIn = false;
30-
31-
private static NetCodeConfig s_ScannedConfig;
32-
private static bool s_ConfigScanned;
33-
3422
[InitializeOnLoadMethod]
3523
private static void OnApplicationStart()
3624
{
37-
// Cross-assembly ordering between the two is not a documented contract.
38-
// Defer rather than racing it.
25+
// N4E assigns NetcodeConfig.Global from its own [InitializeOnLoadMethod] and creates the asset when
26+
// there is none. delayCall runs after those have completed, which is what makes Global reliable here
27+
// without a lookup of our own.
3928
EditorApplication.delayCall += OnDelayCall;
4029
}
4130

@@ -46,7 +35,7 @@ private static void OnDelayCall()
4635
}
4736

4837
/// <summary>
49-
/// Writes the NGO hybrid mode defaults into the project's <see cref="NetCodeConfig"/>.
38+
/// Writes the NGO hybrid mode defaults into the project's <see cref="NetcodeConfig"/>.
5039
/// </summary>
5140
/// <param name="force">
5241
/// Driven by the button in Project Settings:
@@ -62,19 +51,14 @@ internal static void ApplyDefaults(bool force)
6251
}
6352

6453
var settings = NetcodeForGameObjectsProjectSettings.instance;
65-
if (RequiresExperimentalOptIn && !settings.EnableUnifiedNetcodeApi)
66-
{
67-
return;
68-
}
69-
7054
if (!force && settings.HybridDefaultsVersion >= HybridNetcodeDefaults.Version)
7155
{
7256
return;
7357
}
7458

7559
// A project with no config yet leaves the marker unrecorded so that the next domain reload tries again.
7660
// N4E creates one on any domain reload that finds none.
77-
var config = ResolveGlobalConfig();
61+
var config = NetcodeConfig.Global;
7862
if (config == null)
7963
{
8064
return;
@@ -84,40 +68,14 @@ internal static void ApplyDefaults(bool force)
8468
{
8569
EditorUtility.SetDirty(config);
8670
AssetDatabase.SaveAssetIfDirty(config);
87-
Debug.Log($"[Netcode] Applied the NGO hybrid mode defaults to '{config.name}'. These are tuned for NGO and can be changed freely; they will not be re-applied automatically. Use Project Settings > Multiplayer > Netcode for GameObjects to restore them.", config);
71+
new ContextualLogger(config).Info(new Context(LogLevel.Developer, $"Applied the hybrid mode defaults to '{config.name}'. These are tuned for Netcode for GameObjects and can be changed freely; they will not be re-applied automatically. Use Project Settings > Multiplayer > Netcode for GameObjects to restore them.").AddTag("Unified"));
8872
}
8973

9074
// Recorded even when the config already matched and nothing was written. Leaving it unrecorded would make
9175
// the next domain reload a first application again, which would revert the user's next edit.
9276
settings.HybridDefaultsVersion = HybridNetcodeDefaults.Version;
9377
settings.SaveSettings();
9478
}
95-
96-
/// <summary>
97-
/// Resolves the config N4E considers global, falling back to a project scan when N4E has not assigned one yet.
98-
/// </summary>
99-
/// <remarks>
100-
/// The scan is done at most once per domain reload, including when it finds nothing, because this is also
101-
/// reached from OnGUI and <see cref="AssetDatabase.FindAssets"/> walks the entire project. A config created
102-
/// after the scan is picked up on the next domain reload.
103-
/// </remarks>
104-
/// <returns>The config to adjust or null if no config exists.</returns>
105-
internal static NetCodeConfig ResolveGlobalConfig()
106-
{
107-
if (NetCodeConfig.Global != null)
108-
{
109-
return NetCodeConfig.Global;
110-
}
111-
112-
if (!s_ConfigScanned)
113-
{
114-
s_ConfigScanned = true;
115-
var guids = AssetDatabase.FindAssets($"t:{nameof(NetCodeConfig)}");
116-
s_ScannedConfig = guids.Length == 1 ? AssetDatabase.LoadAssetAtPath<NetCodeConfig>(AssetDatabase.GUIDToAssetPath(guids[0])) : null;
117-
}
118-
119-
return s_ScannedConfig;
120-
}
12179
}
12280
}
12381
#endif

‎com.unity.netcode.gameobjects/Editor/Configuration/NetcodeForGameObjectsProjectSettings.cs‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,12 @@ private void OnEnable()
3939

4040
#if UNIFIED_NETCODE
4141
/// <summary>
42-
/// Whether the user has opted into the experimental unified netcode API.
42+
/// The version of the hybrid mode default values already written into this project's NetcodeConfig, or zero
43+
/// when they have never been written.
4344
/// </summary>
4445
/// <remarks>
45-
/// Only consulted while <see cref="HybridNetcodeConfigApplier.RequiresExperimentalOptIn"/> holds. Turning it
46-
/// off again hides the hybrid section and leaves the NetCodeConfig exactly as it is; the marker below is what
47-
/// keeps turning it back on from overwriting anything.
48-
/// </remarks>
49-
[SerializeField]
50-
public bool EnableUnifiedNetcodeApi;
51-
52-
/// <summary>
53-
/// The hybrid mode default values already applied to this project's NetCodeConfig.
54-
/// </summary>
55-
/// <remarks>
56-
/// Zero means they have never been applied. Persisting this value is what keeps the tuned values a one-shot.
57-
/// For users who deliberately change them, they are not overwritten on the next domain reload.
46+
/// A version rather than a flag so a later revision of those values re-applies exactly once. Recording it is
47+
/// what keeps them a one-shot: a user who changes them is not overwritten on the next domain reload.
5848
/// </remarks>
5949
[SerializeField]
6050
public int HybridDefaultsVersion;

‎com.unity.netcode.gameobjects/Editor/Configuration/NetcodeSettingsProvider.cs‎

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Collections.Generic;
22
using System.IO;
3-
#if UNIFIED_NETCODE
4-
using Unity.NetCode;
3+
#if UNIFIED_NETCODE && !UNIFIED_NETCODE_7_0_0
4+
using NetcodeConfig = Unity.NetCode.NetCodeConfig;
55
#endif
66
using UnityEditor;
77
using UnityEngine;
@@ -14,9 +14,6 @@ internal static class NetcodeSettingsProvider
1414
{
1515
private const float k_MaxLabelWidth = 450f;
1616
private static float s_MaxLabelWidth;
17-
#if UNIFIED_NETCODE
18-
private static float s_HybridLabelWidth;
19-
#endif
2017
private static bool s_ShowEditorSettingFields = true;
2118
private static bool s_ShowProjectSettingFields = true;
2219

@@ -218,29 +215,24 @@ private static void OnGuiHandler(string obj)
218215

219216
#if UNIFIED_NETCODE
220217
/// <summary>
221-
/// Displays the NetCodeConfig the NGO hybrid mode defaults were written into, and offers a way to restore
218+
/// Displays the NetcodeConfig the NGO hybrid mode defaults were written into, and offers a way to restore
222219
/// those defaults for anyone who has since changed them.
223220
/// </summary>
224-
/// <param name="settings">The project settings holding the opt-in flag and the applied-defaults marker.</param>
221+
/// <param name="settings">The project settings holding the applied-defaults marker.</param>
225222
private static void DrawHybridSettings(NetcodeForGameObjectsProjectSettings settings)
226223
{
227-
if (HybridNetcodeConfigApplier.RequiresExperimentalOptIn && !DrawUnifiedNetcodeApiToggle(settings))
228-
{
229-
return;
230-
}
231-
232224
GUILayout.BeginVertical("Box");
233225
GUILayout.Label("Hybrid (Netcode for Entities)", EditorStyles.boldLabel);
234226

235-
var config = HybridNetcodeConfigApplier.ResolveGlobalConfig();
227+
var config = NetcodeConfig.Global;
236228
if (config == null)
237229
{
238-
EditorGUILayout.HelpBox("No NetCodeConfig could be resolved. Open Project Settings > Multiplayer, which creates one, then reload the project.", MessageType.Warning);
230+
EditorGUILayout.HelpBox("No NetcodeConfig has been assigned yet. Open Project Settings > Multiplayer, which creates one, then reload the project.", MessageType.Warning);
239231
GUILayout.EndVertical();
240232
return;
241233
}
242234

243-
EditorGUILayout.ObjectField(new GUIContent("Applied to", "The NetCodeConfig that Netcode for GameObjects wrote its hybrid mode defaults into."), config, typeof(NetCodeConfig), false);
235+
EditorGUILayout.ObjectField(new GUIContent("Applied to", "The NetcodeConfig that Netcode for GameObjects wrote its hybrid mode defaults into."), config, typeof(NetcodeConfig), false);
244236

245237
if (settings.HybridDefaultsVersion < HybridNetcodeDefaults.Version)
246238
{
@@ -254,44 +246,6 @@ private static void DrawHybridSettings(NetcodeForGameObjectsProjectSettings sett
254246

255247
GUILayout.EndVertical();
256248
}
257-
258-
/// <summary>
259-
/// Draws the opt-in for the experimental unified netcode API, writing the NGO hybrid mode defaults the first
260-
/// time it is checked.
261-
/// </summary>
262-
/// <param name="settings">The project settings holding the opt-in flag.</param>
263-
/// <returns>Whether the rest of the hybrid section should draw.</returns>
264-
private static bool DrawUnifiedNetcodeApiToggle(NetcodeForGameObjectsProjectSettings settings)
265-
{
266-
const string enableUnifiedApiString = "Enable the experimental unified netcode API";
267-
268-
if (s_HybridLabelWidth == 0)
269-
{
270-
s_HybridLabelWidth = Mathf.Min(k_MaxLabelWidth, EditorStyles.label.CalcSize(new GUIContent(enableUnifiedApiString)).x);
271-
}
272-
273-
EditorGUIUtility.labelWidth = s_HybridLabelWidth;
274-
var enabled = EditorGUILayout.Toggle(
275-
new GUIContent(
276-
enableUnifiedApiString,
277-
"When enabled, Netcode for GameObjects writes the NetCodeConfig values it recommends for hybrid " +
278-
"mode. Disabling it again hides these settings and leaves the NetCodeConfig as it is."),
279-
settings.EnableUnifiedNetcodeApi,
280-
GUILayout.Width(s_HybridLabelWidth + 20));
281-
EditorGUIUtility.labelWidth = s_MaxLabelWidth;
282-
283-
if (enabled != settings.EnableUnifiedNetcodeApi)
284-
{
285-
settings.EnableUnifiedNetcodeApi = enabled;
286-
settings.SaveSettings();
287-
if (enabled)
288-
{
289-
HybridNetcodeConfigApplier.ApplyDefaults(false);
290-
}
291-
}
292-
293-
return enabled;
294-
}
295249
#endif
296250
}
297251

0 commit comments

Comments
 (0)