Skip to content

Commit d48c2f3

Browse files
author
Unity Technologies
committed
## [1.0.17] - 2023-09-11 ### Added * defining ENABLE_UNITY_RPC_REGISTRATION_LOGGING will now log information about registered RPCs during netcode startup ### Changed * NetcodePacket debug log filenames changed to include date/time and version information ### Fixed * addressed a case where it was possible for an exception to be thrown on the server if an RPC was queued for a then dropped connection. * "AssetDatabase.RegisterCustomDependency are restricted during importing" exception thrown by the NetCodeClientSettings, NetCodeClientServerSettings, NetCodeServerSettings in their OnDisable method, when using 2023.2 or newer.
1 parent 933c8cf commit d48c2f3

11 files changed

+151
-137
lines changed

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
# Changelog
22

33

4+
## [1.0.17] - 2023-09-11
5+
6+
### Added
7+
8+
* defining ENABLE_UNITY_RPC_REGISTRATION_LOGGING will now log information about registered RPCs during netcode startup
9+
10+
### Changed
11+
12+
* NetcodePacket debug log filenames changed to include date/time and version information
13+
14+
### Fixed
15+
16+
* addressed a case where it was possible for an exception to be thrown on the server if an RPC was queued for a then dropped connection.
17+
* "AssetDatabase.RegisterCustomDependency are restricted during importing" exception thrown by the NetCodeClientSettings, NetCodeClientServerSettings, NetCodeServerSettings in their OnDisable method, when using 2023.2 or newer.
18+
19+
420
## [1.0.15] - 2023-07-27
521

622
### Changed
723

824
* Updated com.unity.entities dependency to 1.0.14
25+
26+
### Removed
27+
928
* Use of non required TempJob allocation and use Allocator.Temp instead.
1029

1130
### Fixed

Runtime/Authoring/Hybrid/NetCodeClientAndServerSettings.cs

+26-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,35 @@ internal void Save()
7373
{
7474
if (AssetDatabase.IsAssetImportWorkerProcess())
7575
return;
76-
Save(true);
7776
((IEntitiesPlayerSettings)this).RegisterCustomDependency();
77+
Save(true);
78+
AssetDatabase.Refresh();
7879
}
7980

80-
private void OnDisable() => Save();
81+
#if UNITY_2023_2_OR_NEWER
82+
private void OnEnable()
83+
{
84+
((IEntitiesPlayerSettings)this).RegisterCustomDependency();
85+
}
86+
#endif
87+
private void OnDisable()
88+
{
89+
#if !UNITY_2023_2_OR_NEWER
90+
Save();
91+
#else
92+
//But the depedency is going to be update when the scriptable is re-enabled.
93+
if (AssetDatabase.IsAssetImportWorkerProcess())
94+
return;
95+
Save(true);
96+
//This safeguard is necessary because the RegisterCustomDependency throw exceptions
97+
//if this is called when the editor is refreshing the database.
98+
if(!EditorApplication.isUpdating)
99+
{
100+
((IEntitiesPlayerSettings)this).RegisterCustomDependency();
101+
AssetDatabase.Refresh();
102+
}
103+
#endif
104+
}
81105
}
82106
}
83107
#endif

Runtime/Authoring/Hybrid/NetCodeClientSettings.cs

+24-1
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,33 @@ internal void Save()
8989
{
9090
if (AssetDatabase.IsAssetImportWorkerProcess())
9191
return;
92+
((IEntitiesPlayerSettings)this).RegisterCustomDependency();
9293
Save(true);
94+
AssetDatabase.Refresh();
95+
}
96+
#if UNITY_2023_2_OR_NEWER
97+
private void OnEnable()
98+
{
9399
((IEntitiesPlayerSettings)this).RegisterCustomDependency();
94100
}
95-
private void OnDisable() { Save(); }
101+
#endif
102+
private void OnDisable()
103+
{
104+
#if !UNITY_2023_2_OR_NEWER
105+
Save();
106+
#else
107+
//But the depedency is going to be update when the scriptable is re-enabled.
108+
if (AssetDatabase.IsAssetImportWorkerProcess())
109+
return;
110+
//This safeguard is necessary because the RegisterCustomDependency throw exceptions
111+
//if this is called when the editor is refreshing the database.
112+
if(!EditorApplication.isUpdating)
113+
{
114+
((IEntitiesPlayerSettings)this).RegisterCustomDependency();
115+
AssetDatabase.Refresh();
116+
}
117+
#endif
118+
}
96119
}
97120

98121
internal class ClientSettings : DotsPlayerSettingsProvider

Runtime/Authoring/Hybrid/NetCodeServerSettings.cs

+26-2
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,37 @@ ScriptableObject IEntitiesPlayerSettings.AsScriptableObject()
7575
}
7676
internal void Save()
7777
{
78-
//The asset importer should never save the data
7978
if (AssetDatabase.IsAssetImportWorkerProcess())
8079
return;
80+
((IEntitiesPlayerSettings)this).RegisterCustomDependency();
8181
Save(true);
82+
AssetDatabase.Refresh();
83+
}
84+
85+
#if UNITY_2023_2_OR_NEWER
86+
private void OnEnable()
87+
{
8288
((IEntitiesPlayerSettings)this).RegisterCustomDependency();
8389
}
84-
private void OnDisable() { Save(); }
90+
#endif
91+
private void OnDisable()
92+
{
93+
#if !UNITY_2023_2_OR_NEWER
94+
Save();
95+
#else
96+
//But the depedency is going to be update when the scriptable is re-enabled.
97+
if (AssetDatabase.IsAssetImportWorkerProcess())
98+
return;
99+
Save(true);
100+
//This safeguard is necessary because the RegisterCustomDependency throw exceptions
101+
//if this is called when the editor is refreshing the database.
102+
if(!EditorApplication.isUpdating)
103+
{
104+
((IEntitiesPlayerSettings)this).RegisterCustomDependency();
105+
AssetDatabase.Refresh();
106+
}
107+
#endif
108+
}
85109
}
86110

87111
internal class ServerSettings : DotsPlayerSettingsProvider

Runtime/Debug/NetDebug.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,25 @@ public void Init(ref FixedString512Bytes logFolder, ref FixedString128Bytes worl
183183
parameters.InitialBufferCapacity *= 64;
184184
parameters.OverflowBufferSize *= 32;
185185

186+
var dateTime = DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss");
187+
var fileName = $"{logFolder}/NetcodePackets-New-{worldName}-{connectionId}-{dateTime}.log";
188+
189+
var next = 0;
190+
while (File.Exists(fileName))
191+
{
192+
fileName = $"{logFolder}/NetcodePackets-New-{worldName}-{connectionId}-{dateTime}-{next}.log";
193+
next++;
194+
195+
if (next >= 100)
196+
{
197+
break;
198+
}
199+
}
200+
186201
m_NetDebugPacketLoggerHandle = new LoggerConfig()
187202
.OutputTemplate("{Message}")
188203
.MinimumLevel.Set(LogLevel.Verbose)
189-
.WriteTo.File($"{logFolder}/NetcodePacket-{worldName}-{connectionId}.log")
204+
.WriteTo.File(fileName)
190205
.CreateLogger(parameters).Handle;
191206
}
192207

Runtime/Rpc/RpcCollection.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal struct RpcData : IComparable<RpcData>
1717
{
1818
public ulong TypeHash;
1919
public PortableFunctionPointer<RpcExecutor.ExecuteDelegate> Execute;
20-
#if ENABLE_UNITY_COLLECTIONS_CHECKS
20+
#if ENABLE_UNITY_COLLECTIONS_CHECKS || UNITY_DOTS_DEBUG
2121
public ComponentType RpcType;
2222
#endif
2323
public int CompareTo(RpcData other)
@@ -169,6 +169,14 @@ internal ulong CalculateVersionHash()
169169
for (int i = 0; i < m_RpcData.Length; ++i)
170170
{
171171
m_RpcTypeHashToIndex.Add(m_RpcData[i].TypeHash, i);
172+
173+
#if ENABLE_UNITY_RPC_REGISTRATION_LOGGING
174+
#if UNITY_DOTS_DEBUG
175+
UnityEngine.Debug.Log(String.Format("NetCode RPC Method hash 0x{0:X} index {1} type {2}", m_RpcData[i].TypeHash, i, m_RpcData[i].RpcType));
176+
#else
177+
UnityEngine.Debug.Log(String.Format("NetCode RPC Method hash {0} index {1}", m_RpcData[i].TypeHash, i));
178+
#endif
179+
#endif
172180
}
173181

174182
ulong hash = m_RpcData[0].TypeHash;

Runtime/Rpc/RpcCommandRequest.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@ void LambdaMethod(Entity entity, int orderIndex, in SendRpcCommandRequest dest,
146146
if (!rpcFromEntity.HasBuffer(dest.TargetConnection))
147147
{
148148
#if ENABLE_UNITY_COLLECTIONS_CHECKS
149-
throw new InvalidOperationException("Cannot send RPC with no remote connection.");
150-
#else
151-
return;
149+
UnityEngine.Debug.LogWarning("Cannot send RPC with no remote connection.");
152150
#endif
151+
return;
153152
}
154153
var buffer = rpcFromEntity[dest.TargetConnection];
155154
rpcQueue.Schedule(buffer, ghostFromEntity, action);
@@ -166,7 +165,9 @@ void LambdaMethod(Entity entity, int orderIndex, in SendRpcCommandRequest dest,
166165
#if ENABLE_UNITY_COLLECTIONS_CHECKS
167166
else
168167
{
169-
throw new InvalidOperationException("Cannot send RPC with no remote connection.");
168+
UnityEngine.Debug.LogWarning("Cannot send RPC with no remote connection.");
169+
170+
return;
170171
}
171172
#endif
172173
}
-110
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
using System.IO;
2-
using System.Linq;
3-
using Unity.NetCode.Hybrid;
41
using UnityEditor;
52
using NUnit.Framework;
63
using Unity.Entities.Build;
7-
using Unity.Entities.Conversion;
8-
using Unity.NetCode.PrespawnTests;
94
using Unity.NetCode.Tests;
10-
using UnityEditor.Build.Reporting;
11-
using UnityEngine;
12-
using UnityEngine.TestTools;
135

146
namespace Unity.Scenes.Editor.Tests
157
{
@@ -36,107 +28,5 @@ public void NetCodeDebugDefine_IsSetForDevelopmentBuild()
3628
EditorUserBuildSettings.development = originalValue;
3729
}
3830
}
39-
40-
#if false
41-
// APV doesn't respect the Ignore attribute to disable tests, so ifdef explicitly
42-
// https://unity.slack.com/archives/C04UGPY27S9/p1683136704435259
43-
[Test]
44-
public void SuccessfulClientBuildTest()
45-
{
46-
// Temporary hack to work around issue where headless no-graphics CI pass would spit out
47-
// `RenderTexture.Create with shadow sampling failed` error, causing this test to fail.
48-
// Feature has been requested to NOT log this error when running headless.
49-
LogAssert.ignoreFailingMessages = true;
50-
51-
var dotsSettings = DotsGlobalSettings.Instance;
52-
var originalPlayerType = dotsSettings.GetPlayerType();
53-
var originalNetCodeClientTarget = NetCodeClientSettings.instance.ClientTarget;
54-
try
55-
{
56-
bool isOSXEditor = Application.platform == RuntimePlatform.OSXEditor;
57-
58-
var buildOptions = new BuildPlayerOptions();
59-
buildOptions.subtarget = 0;
60-
buildOptions.target = EditorUserBuildSettings.activeBuildTarget;
61-
62-
var scene = SubSceneHelper.CreateEmptyScene(ScenePath, "Parent");
63-
SubSceneHelper.CreateSubScene(scene, Path.GetDirectoryName(scene.path), "Sub0", 5, 5, null, Vector3.zero);
64-
65-
buildOptions.scenes = new string[] {scene.path};
66-
var uniqueTempPath = FileUtil.GetUniqueTempPathInProject();
67-
buildOptions.locationPathName = uniqueTempPath + "/Test.exe";
68-
69-
if(isOSXEditor)
70-
buildOptions.locationPathName = uniqueTempPath + "/Test.app";
71-
buildOptions.extraScriptingDefines = new string[] {"UNITY_CLIENT"};
72-
73-
NetCodeClientSettings.instance.ClientTarget = NetCodeClientTarget.Client;
74-
75-
var report = BuildPipeline.BuildPlayer(buildOptions);
76-
77-
EnsureResourceCatalogHasBeenDeployed(uniqueTempPath, isOSXEditor, report);
78-
}
79-
finally
80-
{
81-
NetCodeClientSettings.instance.ClientTarget = originalNetCodeClientTarget;
82-
}
83-
}
84-
85-
[Test]
86-
public void SuccessfulClientAndServerBuildTest()
87-
{
88-
// Temporary hack to work around issue where headless no-graphics CI pass would spit out
89-
// `RenderTexture.Create with shadow sampling failed` error, causing this test to fail.
90-
// Feature has been requested to NOT log this error when running headless.
91-
LogAssert.ignoreFailingMessages = true;
92-
93-
var dotsSettings = DotsGlobalSettings.Instance;
94-
var originalPlayerType = dotsSettings.GetPlayerType();
95-
var originalNetCodeClientTarget = NetCodeClientSettings.instance.ClientTarget;
96-
try
97-
{
98-
bool isOSXEditor = Application.platform == RuntimePlatform.OSXEditor;
99-
100-
var buildOptions = new BuildPlayerOptions();
101-
buildOptions.subtarget = 0;
102-
buildOptions.target = EditorUserBuildSettings.activeBuildTarget;
103-
104-
var scene = SubSceneHelper.CreateEmptyScene(ScenePath, "Parent");
105-
SubSceneHelper.CreateSubScene(scene, Path.GetDirectoryName(scene.path), "Sub0", 5, 5, null, Vector3.zero);
106-
buildOptions.scenes = new string[] {scene.path};
107-
var uniqueTempPath = FileUtil.GetUniqueTempPathInProject();
108-
buildOptions.locationPathName = uniqueTempPath + "/Test.exe";
109-
110-
if(isOSXEditor)
111-
buildOptions.locationPathName = uniqueTempPath + "/Test.app";
112-
113-
NetCodeClientSettings.instance.ClientTarget = NetCodeClientTarget.ClientAndServer;
114-
115-
var report = BuildPipeline.BuildPlayer(buildOptions);
116-
117-
EnsureResourceCatalogHasBeenDeployed(uniqueTempPath, isOSXEditor, report);
118-
}
119-
finally
120-
{
121-
NetCodeClientSettings.instance.ClientTarget = originalNetCodeClientTarget;
122-
}
123-
}
124-
#endif
125-
126-
static void EnsureResourceCatalogHasBeenDeployed(string uniqueTempPath, bool isOSXEditor, BuildReport report)
127-
{
128-
var locationPath = Application.dataPath + "/../" + uniqueTempPath;
129-
var streamingAssetPath = locationPath + "/Test_Data/StreamingAssets/";
130-
if(isOSXEditor)
131-
streamingAssetPath = locationPath + $"/Test.app/Contents/Resources/Data/StreamingAssets/";
132-
133-
// REDO: Just check the resource catalog has been deployed
134-
var sceneInfoFileRelativePath = EntityScenesPaths.FullPathForFile(streamingAssetPath, EntityScenesPaths.RelativePathForSceneInfoFile);
135-
var resourceCatalogFileExists = File.Exists(sceneInfoFileRelativePath);
136-
var reportMessages = string.Join('\n', report.steps.SelectMany(x => x.messages).Select(x => $"[{x.type}] {x.content}"));
137-
var stringReport = $"[{report.summary.result}, {report.summary.totalErrors} totalErrors, {report.summary.totalWarnings} totalWarnings, resourceCatalogFileExists: {resourceCatalogFileExists}]\nBuild logs ----------\n{reportMessages} ------ ";
138-
Assert.AreEqual(BuildResult.Succeeded, report.summary.result, $"Expected build success! Report: {stringReport}");
139-
Assert.IsTrue(resourceCatalogFileExists, $"Expected '{sceneInfoFileRelativePath}' file to exist! Report: {stringReport}");
140-
}
14131
}
14232
}

Tests/Editor/RpcTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void Rpc_ServerBroadcast_Works()
127127
}
128128

129129
[Test]
130-
public void Rpc_SendingBeforeGettingNetworkId_Throws()
130+
public void Rpc_SendingBeforeGettingNetworkId_LogWarning()
131131
{
132132
using (var testWorld = new NetCodeTestWorld())
133133
{
@@ -145,7 +145,7 @@ public void Rpc_SendingBeforeGettingNetworkId_Throws()
145145
// Connect and make sure the connection could be established
146146
Assert.IsTrue(testWorld.Connect(frameTime, 4));
147147

148-
LogAssert.Expect(LogType.Exception, new Regex("InvalidOperationException: Cannot send RPC with no remote connection."));
148+
LogAssert.Expect(LogType.Warning, new Regex("Cannot send RPC with no remote connection."));
149149
for (int i = 0; i < 33; ++i)
150150
testWorld.Tick(1f / 60f);
151151

ValidationExceptions.json

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
{
2-
"ErrorExceptions": [
3-
{
4-
"ValidationTest": "Package Unity Version Validation",
5-
"ExceptionMessage": "The Unity version requirement is more strict than in the previous version of the package. Increment the minor version of the package to leave patch versions available for previous version. Read more about this error and potential solutions at https://docs.unity3d.com/Packages/com.unity.package-validation-suite@latest/index.html?preview=1&subfolder=/manual/package_unity_version_validation_error.html#the-unity-version-requirement-is-more-strict-than-in-the-previous-version-of-the-package",
6-
"PackageVersion": "1.0.15"
7-
}
8-
],
9-
"WarningExceptions": []
2+
"ErrorExceptions": [
3+
{
4+
"ValidationTest": "Package Unity Version Validation",
5+
"ExceptionMessage": "The Unity version requirement is more strict than in the previous version of the package. Increment the minor version of the package to leave patch versions available for previous version. Read more about this error and potential solutions at https://docs.unity3d.com/Packages/com.unity.package-validation-suite@latest/index.html?preview=1&subfolder=/manual/package_unity_version_validation_error.html#the-unity-version-requirement-is-more-strict-than-in-the-previous-version-of-the-package",
6+
"PackageVersion": "1.0.17"
7+
},
8+
{
9+
"ValidationTest": "API Validation",
10+
"ExceptionMessage": "New assembly \"Unity.NetCode.TestsUtils\" may only be added in a new minor or major version.",
11+
"PackageVersion": "1.0.17"
12+
},
13+
{
14+
"ValidationTest": "API Validation",
15+
"ExceptionMessage": "Additions require a new minor or major version.",
16+
"PackageVersion": "1.0.17"
17+
}
18+
],
19+
"WarningExceptions": []
1020
}

0 commit comments

Comments
 (0)