Skip to content

Commit d10c6d5

Browse files
Merge branch 'develop' into docs/toc-changes-backport
2 parents af2d5cf + 3250ff6 commit d10c6d5

File tree

12 files changed

+94
-6
lines changed

12 files changed

+94
-6
lines changed

.yamato/_run-all.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#-----------------------------------------------------------------------------------
1212

13+
1314
# This job runs the fastest checks (PVP and code standards)
1415
# This is mainly used to quickly validate the easy mistakes before for example running PR trigger jobs (see _triggers.yml)
1516
run_quick_checks:

.yamato/code-coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ code_coverage_{{ platform.name }}_{{ editor }}:
3838
commands:
3939
- unity-downloader-cli --fast --wait -u {{ editor }} -c Editor {% if platform.name == "mac" %} --arch arm64 {% endif %} # For macOS we use ARM64 models
4040
- upm-pvp create-test-project test-project --packages "upm-ci~/packages/*.tgz" --unity .Editor
41-
- UnifiedTestRunner --suite=editor --suite=playmode --editor-location=.Editor --testproject=test-project --enable-code-coverage coverage-upload-options="reportsDir:$PWD/test-results/CoverageResults;name:NGOv1_{{ platform.name }}_{{ editor }};flags:NGOv1_{{ platform.name }}_{{ editor }};verbose" --coverage-results-path=$PWD/test-results/CoverageResults --coverage-options="generateHtmlReport;generateAdditionalMetrics;assemblyFilters:+Unity.Netcode.Editor,+Unity.Netcode.Runtime" --extra-editor-arg=--burst-disable-compilation --timeout={ test_timeout }} --rerun-strategy=Test --retry={{ num_test_retries }} --clean-library-on-rerun --artifacts-path=test-results
41+
- UnifiedTestRunner --suite=editor --suite=playmode --editor-location=.Editor --testproject=test-project --enable-code-coverage coverage-upload-options="reportsDir:$PWD/test-results/CoverageResults;name:NGOv1_{{ platform.name }}_{{ editor }};flags:NGOv1_{{ platform.name }}_{{ editor }};verbose" --coverage-results-path=$PWD/test-results/CoverageResults --coverage-options="generateHtmlReport;generateAdditionalMetrics;assemblyFilters:+Unity.Netcode.Editor,+Unity.Netcode.Runtime" --extra-editor-arg=--burst-disable-compilation --timeout={{ test_timeout }} --rerun-strategy=Test --retry={{ num_test_retries }} --clean-library-on-rerun --artifacts-path=test-results
4242
artifacts:
4343
logs:
4444
paths:

.yamato/project-builders/project-builders.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ build_{{ netcodeProject[0] }}_project:
3434
commands:
3535
# Validate inputs passed via Yamato variables
3636
- python Tools/scripts/BuildAutomation/validate_params.py
37-
- echo Building {{ netcodeProject[0] }} project from branch {{ netcodeProject[1].defaultBranch }} with Unity version of %UNITY_VERSION%, Scripting backend %SCRIPTING_BACKEND_IL2CPP_MONO%, Burst %BURST_ON_OFF% for platform %PLATFORM_WIN64_MAC_ANDROID%
37+
- echo Building {{ netcodeProject[0] }} project from branch %SAMPLE_BRANCH% with Unity version of %UNITY_VERSION%, Scripting backend %SCRIPTING_BACKEND_IL2CPP_MONO%, Burst %BURST_ON_OFF% for platform %PLATFORM_WIN64_MAC_ANDROID%
3838

3939
# Clone the external project repository into a specific directory. Notice that branch is also specified.
4040
- git clone --single-branch --branch %SAMPLE_BRANCH% {{ netcodeProject[1].GithubRepo }} C:/ClonedProject

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1313

1414
### Changed
1515

16+
- Better error message when using generic IEquatable in a generic INetworkSerializable class and updated documentation with workaround. (#3744)
1617
- The `NetworkManager` functions `GetTransportIdFromClientId` and `GetClientIdFromTransportId` will now return `ulong.MaxValue` when the clientId or transportId do not exist. (#3721)
1718
- Changed minimum Unity version supported to 2022.3 LTS
1819

@@ -25,6 +26,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2526
### Fixed
2627

2728
- Multiple disconnect events from the same transport will no longer disconnect the host. (#3721)
29+
- Exception when the network prefab list in the network manager has uninitialized elements. (#3744)
2830

2931
### Security
3032

com.unity.netcode.gameobjects/Documentation~/advanced-topics/serialization/inetworkserializable.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,55 @@ public struct MyStructB : MyStructA
181181
}
182182
}
183183
```
184+
185+
## Generic IEquatable network variables
186+
187+
Netcode for GameObjects doesn't support generic `INetworkSerializable` types with generic `IEquatable`s when implemented as `public class NotSupported<T> : INetworkSerializable, IEquatable<NotSupported<T>>`, where the type is passed in during declaration like `NetworkVariable<NotSupported<int>> myVar;`.
188+
189+
You can work around this limitation by creating the generic class as normal and adding a virtual method for handling the serialization of the type. Then wrap the generic `INetworkSerializable` in a derived class that has a serializable type defined where the implementation for the serialization is provided.
190+
191+
For example:
192+
193+
```csharp
194+
public class MyGameData<T> : INetworkSerializable
195+
{
196+
// This needs to be a serializable type according to what network variables support
197+
public T Data;
198+
199+
protected virtual void OnNetworkSerialize<T2>(BufferSerializer<T2> serializer) where T2 : IReaderWriter
200+
{
201+
}
202+
203+
public void NetworkSerialize<T2>(BufferSerializer<T2> serializer) where T2 : IReaderWriter
204+
{
205+
OnNetworkSerialize(serializer);
206+
}
207+
}
208+
209+
public class GameDataWithLong : MyGameData<long>, IEquatable<GameDataWithLong>
210+
{
211+
// Potential additional data
212+
public int AdditionalData;
213+
214+
protected virtual bool OnEquals(GameDataWithLong other)
215+
{
216+
return other.Data.Equals(other);
217+
}
218+
public bool Equals(GameDataWithLong other)
219+
{
220+
return OnEquals(other);
221+
}
222+
223+
protected override void OnNetworkSerialize<T2>(BufferSerializer<T2> serializer)
224+
{
225+
serializer.SerializeValue(ref AdditionalData);
226+
serializer.SerializeValue(ref Data);
227+
}
228+
}
229+
```
230+
231+
Then declare this network variable like so:
232+
233+
```csharp
234+
NetworkVariable<GameDataWithLong> myVar = new NetworkVariable<GameDataWithLong>();
235+
```

com.unity.netcode.gameobjects/Editor/CodeGen/NetworkBehaviourILPP.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,14 @@ private void CreateNetworkVariableTypeInitializers(AssemblyDefinition assembly,
408408
}
409409
else
410410
{
411-
m_Diagnostics.AddError($"{type}: Managed type in NetworkVariable must implement IEquatable<{type}>");
411+
foreach (var typeInterface in type.Resolve().Interfaces)
412+
{
413+
if (typeInterface.InterfaceType.Name.Contains(typeof(IEquatable<>).Name) && typeInterface.InterfaceType.IsGenericInstance)
414+
{
415+
m_Diagnostics.AddError($"{type}: A generic IEquatable '{typeInterface.InterfaceType.FullName}' is not supported.");
416+
}
417+
}
418+
m_Diagnostics.AddError($"{type}: Managed type in NetworkVariable must implement IEquatable<{type}>.");
412419
equalityMethod = new GenericInstanceMethod(m_NetworkVariableSerializationTypes_InitializeEqualityChecker_ManagedClassEquals_MethodRef);
413420
}
414421

com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7+
using System.Linq;
78
using Unity.Netcode.Editor.Configuration;
89
using UnityEditor;
910
using UnityEngine;
@@ -539,6 +540,10 @@ private void DrawPrefabListField()
539540
{
540541
EditorGUILayout.HelpBox("You have no prefab list selected. You will have to add your prefabs manually at runtime for netcode to work.", MessageType.Warning);
541542
}
543+
else if (m_NetworkManager.NetworkConfig.Prefabs.NetworkPrefabsLists.All(x => x == null))
544+
{
545+
EditorGUILayout.HelpBox("All prefab lists selected are uninitialized. You will have to add your prefabs manually at runtime for netcode to work.", MessageType.Warning);
546+
}
542547

543548
EditorGUILayout.PropertyField(m_PrefabsList);
544549
return;

com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefabs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ internal void Shutdown()
9393
public void Initialize(bool warnInvalid = true)
9494
{
9595
m_Prefabs.Clear();
96+
NetworkPrefabsLists.RemoveAll(x => x == null);
9697
foreach (var list in NetworkPrefabsLists)
9798
{
9899
list.OnAdd += AddTriggeredByNetworkPrefabList;

com.unity.netcode.gameobjects/Runtime/HelpUrls.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ internal static class HelpUrls
1010
public const string NetworkManager = k_BaseManualUrl + "components/core/networkmanager.html";
1111
public const string NetworkObject = k_BaseManualUrl + "components/core/networkobject.html";
1212
public const string NetworkAnimator = k_BaseManualUrl + "components/helper/networkanimator.html";
13-
public const string NetworkRigidbody = k_BaseManualUrl + "advanced-topics/physics.html#networkrigidbody";
14-
public const string NetworkRigidbody2D = k_BaseManualUrl + "advanced-topics/physics.html#networkrigidbody2d";
13+
public const string NetworkRigidbody = k_BaseManualUrl + "components/helper/networkrigidbody.html";
14+
public const string NetworkRigidbody2D = k_BaseManualUrl + "components/helper/networkrigidbody.html#networkrigidbody2d";
1515
public const string NetworkTransform = k_BaseManualUrl + "components/helper/networktransform.html";
1616
public const string AnticipatedNetworkTransform = k_BaseManualUrl + "advanced-topics/client-anticipation.html";
1717
public const string UnityTransport = k_BaseApiUrl + ".Transports.UTP.UnityTransport.html";

com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,10 @@ private void ExtractNetworkMetrics()
10481048
continue;
10491049
}
10501050
var transportClientId = NetworkManager.ConnectionManager.ClientIdToTransportId(ngoConnectionId);
1051-
ExtractNetworkMetricsForClient(transportClientId);
1051+
if (transportClientId.Item2)
1052+
{
1053+
ExtractNetworkMetricsForClient(transportClientId.Item1);
1054+
}
10521055
}
10531056
}
10541057
else

0 commit comments

Comments
 (0)