com.unity.netcode.gameobjects@1.1.0

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).

## [1.1.0] - 2022-10-21

### Added

- Added `NetworkManager.IsApproved` flag that is set to `true` a client has been approved.(#2261)
- `UnityTransport` now provides a way to set the Relay server data directly from the `RelayServerData` structure (provided by the Unity Transport package) throuh its `SetRelayServerData` method. This allows making use of the new APIs in UTP 1.3 that simplify integration of the Relay SDK. (#2235)
- IPv6 is now supported for direct connections when using `UnityTransport`. (#2232)
- Added WebSocket support when using UTP 2.0 with `UseWebSockets` property in the `UnityTransport` component of the `NetworkManager` allowing to pick WebSockets for communication. When building for WebGL, this selection happens automatically. (#2201)
- Added position, rotation, and scale to the `ParentSyncMessage` which provides users the ability to specify the final values on the server-side when `OnNetworkObjectParentChanged` is invoked just before the message is created (when the `Transform` values are applied to the message). (#2146)
- Added `NetworkObject.TryRemoveParent` method for convenience purposes opposed to having to cast null to either `GameObject` or `NetworkObject`. (#2146)

### Changed

- Updated `UnityTransport` dependency on `com.unity.transport` to 1.3.0. (#2231)
- The send queues of `UnityTransport` are now dynamically-sized. This means that there shouldn't be any need anymore to tweak the 'Max Send Queue Size' value. In fact, this field is now removed from the inspector and will not be serialized anymore. It is still possible to set it manually using the `MaxSendQueueSize` property, but it is not recommended to do so aside from some specific needs (e.g. limiting the amount of memory used by the send queues in very constrained environments). (#2212)
- As a consequence of the above change, the `UnityTransport.InitialMaxSendQueueSize` field is now deprecated. There is no default value anymore since send queues are dynamically-sized. (#2212)
- The debug simulator in `UnityTransport` is now non-deterministic. Its random number generator used to be seeded with a constant value, leading to the same pattern of packet drops, delays, and jitter in every run. (#2196)
- `NetworkVariable<>` now supports managed `INetworkSerializable` types, as well as other managed types with serialization/deserialization delegates registered to `UserNetworkVariableSerialization<T>.WriteValue` and `UserNetworkVariableSerialization<T>.ReadValue` (#2219)
- `NetworkVariable<>` and `BufferSerializer<BufferSerializerReader>` now deserialize `INetworkSerializable` types in-place, rather than constructing new ones. (#2219)

### Fixed

- Fixed `NetworkManager.ApprovalTimeout` will not timeout due to slower client synchronization times as it now uses the added `NetworkManager.IsApproved` flag to determined if the client has been approved or not.(#2261)
- Fixed issue caused when changing ownership of objects hidden to some clients (#2242)
- Fixed issue where an in-scene placed NetworkObject would not invoke NetworkBehaviour.OnNetworkSpawn if the GameObject was disabled when it was despawned. (#2239)
- Fixed issue where clients were not rebuilding the `NetworkConfig` hash value for each unique connection request. (#2226)
- Fixed the issue where player objects were not taking the `DontDestroyWithOwner` property into consideration when a client disconnected. (#2225)
- Fixed issue where `SceneEventProgress` would not complete if a client late joins while it is still in progress. (#2222)
- Fixed issue where `SceneEventProgress` would not complete if a client disconnects. (#2222)
- Fixed issues with detecting if a `SceneEventProgress` has timed out. (#2222)
- Fixed issue #1924 where `UnityTransport` would fail to restart after a first failure (even if what caused the initial failure was addressed). (#2220)
- Fixed issue where `NetworkTransform.SetStateServerRpc` and `NetworkTransform.SetStateClientRpc` were not honoring local vs world space settings when applying the position and rotation. (#2203)
- Fixed ILPP `TypeLoadException` on WebGL on MacOS Editor and potentially other platforms. (#2199)
- Implicit conversion of NetworkObjectReference to GameObject will now return null instead of throwing an exception if the referenced object could not be found (i.e., was already despawned) (#2158)
- Fixed warning resulting from a stray NetworkAnimator.meta file (#2153)
- Fixed Connection Approval Timeout not working client side. (#2164)
- Fixed issue where the `WorldPositionStays` parenting parameter was not being synchronized with clients. (#2146)
- Fixed issue where parented in-scene placed `NetworkObject`s would fail for late joining clients. (#2146)
- Fixed issue where scale was not being synchronized which caused issues with nested parenting and scale when `WorldPositionStays` was true. (#2146)
- Fixed issue with `NetworkTransform.ApplyTransformToNetworkStateWithInfo` where it was not honoring axis sync settings when `NetworkTransformState.IsTeleportingNextFrame` was true. (#2146)
- Fixed issue with `NetworkTransform.TryCommitTransformToServer` where it was not honoring the `InLocalSpace` setting. (#2146)
- Fixed ClientRpcs always reporting in the profiler view as going to all clients, even when limited to a subset of clients by `ClientRpcParams`. (#2144)
- Fixed RPC codegen failing to choose the correct extension methods for `FastBufferReader` and `FastBufferWriter` when the parameters were a generic type (i.e., List<int>) and extensions for multiple instantiations of that type have been defined (i.e., List<int> and List<string>) (#2142)
- Fixed the issue where running a server (i.e. not host) the second player would not receive updates (unless a third player joined). (#2127)
- Fixed issue where late-joining client transition synchronization could fail when more than one transition was occurring.(#2127)
- Fixed throwing an exception in `OnNetworkUpdate` causing other `OnNetworkUpdate` calls to not be executed. (#1739)
- Fixed synchronization when Time.timeScale is set to 0. This changes timing update to use unscaled deltatime. Now network updates rate are independent from the local time scale. (#2171)
- Fixed not sending all NetworkVariables to all clients when a client connects to a server. (#1987)
- Fixed IsOwner/IsOwnedByServer being wrong on the server after calling RemoveOwnership (#2211)
This commit is contained in:
Unity Technologies
2022-10-21 00:00:00 +00:00
parent a6969670f5
commit 1e7078c160
97 changed files with 6175 additions and 1643 deletions

View File

@@ -2,7 +2,6 @@
#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using Unity.Multiplayer.Tools.MetricTypes;
using Unity.Netcode.TestHelpers.Runtime;

View File

@@ -5,7 +5,6 @@ using NUnit.Framework;
using Unity.Multiplayer.Tools.NetStats;
using UnityEngine.TestTools;
using Unity.Netcode.TestHelpers.Runtime;
using Unity.Netcode.TestHelpers.Runtime.Metrics;
namespace Unity.Netcode.RuntimeTests.Metrics
{

View File

@@ -1,5 +1,4 @@
#if MULTIPLAYER_TOOLS
using System;
using System.Collections;
using System.Linq;
using NUnit.Framework;
@@ -36,7 +35,7 @@ namespace Unity.Netcode.RuntimeTests.Metrics
private NetworkObject SpawnNetworkObject()
{
// Spawn another network object so we can hide multiple.
var gameObject = UnityEngine.Object.Instantiate(m_NewNetworkPrefab); // new GameObject(NewNetworkObjectName);
var gameObject = Object.Instantiate(m_NewNetworkPrefab); // new GameObject(NewNetworkObjectName);
var networkObject = gameObject.GetComponent<NetworkObject>();
networkObject.NetworkManagerOwner = Server;
networkObject.Spawn();
@@ -62,6 +61,13 @@ namespace Unity.Netcode.RuntimeTests.Metrics
var ownershipChangeSent = metricValues.First();
Assert.AreEqual(networkObject.NetworkObjectId, ownershipChangeSent.NetworkId.NetworkId);
Assert.AreEqual(Server.LocalClientId, ownershipChangeSent.Connection.Id);
Assert.AreEqual(0, ownershipChangeSent.BytesCount);
// The first metric is to the server(self), so its size is now correctly reported as 0.
// Let's check the last one instead, to have a valid value
ownershipChangeSent = metricValues.Last();
Assert.AreEqual(networkObject.NetworkObjectId, ownershipChangeSent.NetworkId.NetworkId);
Assert.AreEqual(Client.LocalClientId, ownershipChangeSent.Connection.Id);
Assert.AreEqual(FastBufferWriter.GetWriteSize<ChangeOwnershipMessage>() + k_MessageHeaderSize, ownershipChangeSent.BytesCount);
}

View File

@@ -1,7 +1,6 @@
#if MULTIPLAYER_TOOLS
#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
using System;
using System.Collections;
using NUnit.Framework;
using Unity.Collections;
@@ -9,7 +8,9 @@ using Unity.Multiplayer.Tools.MetricTypes;
using Unity.Netcode.TestHelpers.Runtime;
using Unity.Netcode.TestHelpers.Runtime.Metrics;
using Unity.Netcode.Transports.UTP;
using UnityEngine;
#if UTP_TRANSPORT_2_0_ABOVE
using Unity.Networking.Transport.Utilities;
#endif
using UnityEngine.TestTools;
namespace Unity.Netcode.RuntimeTests.Metrics
@@ -18,16 +19,25 @@ namespace Unity.Netcode.RuntimeTests.Metrics
{
protected override int NumberOfClients => 1;
private readonly int m_PacketLossRate = 25;
private readonly int m_PacketLossRangeDelta = 5;
private readonly int m_PacketLossRangeDelta = 3;
private readonly int m_MessageSize = 200;
public PacketLossMetricsTests()
: base(HostOrServer.Server)
{}
{ }
protected override void OnServerAndClientsCreated()
{
var clientTransport = (UnityTransport)m_ClientNetworkManagers[0].NetworkConfig.NetworkTransport;
#if !UTP_TRANSPORT_2_0_ABOVE
clientTransport.SetDebugSimulatorParameters(0, 0, m_PacketLossRate);
#endif
// Determined through trial and error. With both UTP 1.2 and 2.0, this random seed
// results in an effective packet loss percentage between 22% and 28%. Future UTP
// updates may change the RNG call patterns and cause this test to fail, in which
// case the value should be modified again.
clientTransport.DebugSimulatorRandomSeed = 4;
base.OnServerAndClientsCreated();
}
@@ -41,11 +51,9 @@ namespace Unity.Netcode.RuntimeTests.Metrics
for (int i = 0; i < 1000; ++i)
{
using (var writer = new FastBufferWriter(sizeof(byte), Allocator.Persistent))
{
writer.WriteByteSafe(42);
m_ServerNetworkManager.CustomMessagingManager.SendNamedMessage("Test", m_ServerNetworkManager.ConnectedClientsIds, writer);
}
using var writer = new FastBufferWriter(m_MessageSize, Allocator.Persistent);
writer.WriteBytesSafe(new byte[m_MessageSize]);
m_ServerNetworkManager.CustomMessagingManager.SendNamedMessage("Test", m_ServerNetworkManager.ConnectedClientsIds, writer);
}
yield return waitForPacketLossMetric.WaitForMetricsReceived();
@@ -57,20 +65,26 @@ namespace Unity.Netcode.RuntimeTests.Metrics
[UnityTest]
public IEnumerator TrackPacketLossAsClient()
{
double packetLossRateMinRange = (m_PacketLossRate-m_PacketLossRangeDelta) / 100d;
double packetLossRateMinRange = (m_PacketLossRate - m_PacketLossRangeDelta) / 100d;
double packetLossRateMaxrange = (m_PacketLossRate + m_PacketLossRangeDelta) / 100d;
var clientNetworkManager = m_ClientNetworkManagers[0];
#if UTP_TRANSPORT_2_0_ABOVE
var clientTransport = (UnityTransport)clientNetworkManager.NetworkConfig.NetworkTransport;
clientTransport.NetworkDriver.CurrentSettings.TryGet<SimulatorUtility.Parameters>(out var parameters);
parameters.PacketDropPercentage = m_PacketLossRate;
clientTransport.NetworkDriver.ModifySimulatorStageParameters(parameters);
#endif
var waitForPacketLossMetric = new WaitForGaugeMetricValues((clientNetworkManager.NetworkMetrics as NetworkMetrics).Dispatcher,
NetworkMetricTypes.PacketLoss,
metric => packetLossRateMinRange <= metric && metric <= packetLossRateMaxrange);
for (int i = 0; i < 1000; ++i)
{
using (var writer = new FastBufferWriter(sizeof(byte), Allocator.Persistent))
{
writer.WriteByteSafe(42);
m_ServerNetworkManager.CustomMessagingManager.SendNamedMessage("Test", m_ServerNetworkManager.ConnectedClientsIds, writer);
}
using var writer = new FastBufferWriter(m_MessageSize, Allocator.Persistent);
writer.WriteBytesSafe(new byte[m_MessageSize]);
m_ServerNetworkManager.CustomMessagingManager.SendNamedMessage("Test", m_ServerNetworkManager.ConnectedClientsIds, writer);
}
yield return waitForPacketLossMetric.WaitForMetricsReceived();

View File

@@ -5,7 +5,6 @@ using NUnit.Framework;
using Unity.Collections;
using Unity.Multiplayer.Tools.MetricTypes;
using UnityEngine.TestTools;
using Unity.Netcode.TestHelpers.Runtime;
using Unity.Netcode.TestHelpers.Runtime.Metrics;
namespace Unity.Netcode.RuntimeTests.Metrics

View File

@@ -2,13 +2,14 @@
using System.Collections;
using System.Linq;
using NUnit.Framework;
using Unity.Collections;
using Unity.Multiplayer.Tools.MetricTypes;
using UnityEngine.TestTools;
using Unity.Netcode.TestHelpers.Runtime.Metrics;
namespace Unity.Netcode.RuntimeTests.Metrics
{
internal class RpcMetricsTests : SingleClientMetricTestBase
internal class RpcMetricsTests : DualClientMetricTestBase
{
protected override void OnCreatePlayerPrefab()
{
@@ -17,30 +18,79 @@ namespace Unity.Netcode.RuntimeTests.Metrics
}
[UnityTest]
public IEnumerator TrackRpcSentMetricOnServer()
public IEnumerator TrackRpcSentMetricOnServerToOnlyOneClientWithArray()
{
var waitForMetricValues = new WaitForEventMetricValues<RpcEvent>(ServerMetrics.Dispatcher, NetworkMetricTypes.RpcSent);
m_PlayerNetworkObjects[m_ServerNetworkManager.LocalClientId][Client.LocalClientId].GetComponent<RpcTestComponent>().MyClientRpc();
m_PlayerNetworkObjects[m_ServerNetworkManager.LocalClientId][FirstClient.LocalClientId].GetComponent<RpcTestComponent>().MyClientRpc(new ClientRpcParams
{
Send = new ClientRpcSendParams
{
TargetClientIds = new[] { FirstClient.LocalClientId }
}
});
yield return waitForMetricValues.WaitForMetricsReceived();
var serverRpcSentValues = waitForMetricValues.AssertMetricValuesHaveBeenFound();
Assert.AreEqual(2, serverRpcSentValues.Count); // Server will receive this, since it's host
Assert.AreEqual(1, serverRpcSentValues.Count);
Assert.That(serverRpcSentValues, Has.All.Matches<RpcEvent>(x => x.Name == nameof(RpcTestComponent.MyClientRpc)));
Assert.That(serverRpcSentValues, Has.All.Matches<RpcEvent>(x => x.NetworkBehaviourName == nameof(RpcTestComponent)));
Assert.That(serverRpcSentValues, Has.All.Matches<RpcEvent>(x => x.BytesCount != 0));
Assert.AreEqual(FirstClient.LocalClientId, serverRpcSentValues.First().Connection.Id);
}
[UnityTest]
public IEnumerator TrackRpcSentMetricOnServerToOnlyOneClientWithNativeArray()
{
var waitForMetricValues = new WaitForEventMetricValues<RpcEvent>(ServerMetrics.Dispatcher, NetworkMetricTypes.RpcSent);
m_PlayerNetworkObjects[m_ServerNetworkManager.LocalClientId][FirstClient.LocalClientId].GetComponent<RpcTestComponent>().MyClientRpc(new ClientRpcParams
{
Send = new ClientRpcSendParams
{
TargetClientIdsNativeArray = new NativeArray<ulong>(new[] { FirstClient.LocalClientId }, Allocator.Temp)
}
});
yield return waitForMetricValues.WaitForMetricsReceived();
var serverRpcSentValues = waitForMetricValues.AssertMetricValuesHaveBeenFound();
Assert.AreEqual(1, serverRpcSentValues.Count);
Assert.That(serverRpcSentValues, Has.All.Matches<RpcEvent>(x => x.Name == nameof(RpcTestComponent.MyClientRpc)));
Assert.That(serverRpcSentValues, Has.All.Matches<RpcEvent>(x => x.NetworkBehaviourName == nameof(RpcTestComponent)));
Assert.That(serverRpcSentValues, Has.All.Matches<RpcEvent>(x => x.BytesCount != 0));
Assert.AreEqual(FirstClient.LocalClientId, serverRpcSentValues.First().Connection.Id);
}
[UnityTest]
public IEnumerator TrackRpcSentMetricOnServerToAllClients()
{
var waitForMetricValues = new WaitForEventMetricValues<RpcEvent>(ServerMetrics.Dispatcher, NetworkMetricTypes.RpcSent);
m_PlayerNetworkObjects[m_ServerNetworkManager.LocalClientId][FirstClient.LocalClientId].GetComponent<RpcTestComponent>().MyClientRpc();
yield return waitForMetricValues.WaitForMetricsReceived();
var serverRpcSentValues = waitForMetricValues.AssertMetricValuesHaveBeenFound();
Assert.AreEqual(3, serverRpcSentValues.Count); // Server will receive this, since it's host
Assert.That(serverRpcSentValues, Has.All.Matches<RpcEvent>(x => x.Name == nameof(RpcTestComponent.MyClientRpc)));
Assert.That(serverRpcSentValues, Has.All.Matches<RpcEvent>(x => x.NetworkBehaviourName == nameof(RpcTestComponent)));
Assert.That(serverRpcSentValues, Has.All.Matches<RpcEvent>(x => x.BytesCount != 0));
Assert.Contains(Server.LocalClientId, serverRpcSentValues.Select(x => x.Connection.Id).ToArray());
Assert.Contains(Client.LocalClientId, serverRpcSentValues.Select(x => x.Connection.Id).ToArray());
Assert.Contains(FirstClient.LocalClientId, serverRpcSentValues.Select(x => x.Connection.Id).ToArray());
Assert.Contains(SecondClient.LocalClientId, serverRpcSentValues.Select(x => x.Connection.Id).ToArray());
}
[UnityTest]
public IEnumerator TrackRpcSentMetricOnClient()
{
var waitForClientMetricsValues = new WaitForEventMetricValues<RpcEvent>(ClientMetrics.Dispatcher, NetworkMetricTypes.RpcSent);
var waitForClientMetricsValues = new WaitForEventMetricValues<RpcEvent>(FirstClientMetrics.Dispatcher, NetworkMetricTypes.RpcSent);
m_PlayerNetworkObjects[Client.LocalClientId][Client.LocalClientId].GetComponent<RpcTestComponent>().MyServerRpc();
m_PlayerNetworkObjects[FirstClient.LocalClientId][FirstClient.LocalClientId].GetComponent<RpcTestComponent>().MyServerRpc();
yield return waitForClientMetricsValues.WaitForMetricsReceived();
@@ -58,7 +108,7 @@ namespace Unity.Netcode.RuntimeTests.Metrics
public IEnumerator TrackRpcReceivedMetricOnServer()
{
var waitForServerMetricsValues = new WaitForEventMetricValues<RpcEvent>(ServerMetrics.Dispatcher, NetworkMetricTypes.RpcReceived);
m_PlayerNetworkObjects[Client.LocalClientId][Client.LocalClientId].GetComponent<RpcTestComponent>().MyServerRpc();
m_PlayerNetworkObjects[FirstClient.LocalClientId][FirstClient.LocalClientId].GetComponent<RpcTestComponent>().MyServerRpc();
yield return waitForServerMetricsValues.WaitForMetricsReceived();
@@ -66,7 +116,7 @@ namespace Unity.Netcode.RuntimeTests.Metrics
Assert.AreEqual(1, serverRpcReceivedValues.Count);
var rpcReceived = serverRpcReceivedValues.First();
Assert.AreEqual(Client.LocalClientId, rpcReceived.Connection.Id);
Assert.AreEqual(FirstClient.LocalClientId, rpcReceived.Connection.Id);
Assert.AreEqual(nameof(RpcTestComponent.MyServerRpc), rpcReceived.Name);
Assert.AreEqual(nameof(RpcTestComponent), rpcReceived.NetworkBehaviourName);
Assert.AreNotEqual(0, rpcReceived.BytesCount);
@@ -75,9 +125,9 @@ namespace Unity.Netcode.RuntimeTests.Metrics
[UnityTest]
public IEnumerator TrackRpcReceivedMetricOnClient()
{
var waitForClientMetricsValues = new WaitForEventMetricValues<RpcEvent>(ClientMetrics.Dispatcher, NetworkMetricTypes.RpcReceived);
var waitForClientMetricsValues = new WaitForEventMetricValues<RpcEvent>(FirstClientMetrics.Dispatcher, NetworkMetricTypes.RpcReceived);
m_PlayerNetworkObjects[m_ServerNetworkManager.LocalClientId][Client.LocalClientId].GetComponent<RpcTestComponent>().MyClientRpc();
m_PlayerNetworkObjects[m_ServerNetworkManager.LocalClientId][FirstClient.LocalClientId].GetComponent<RpcTestComponent>().MyClientRpc();
yield return waitForClientMetricsValues.WaitForMetricsReceived();

View File

@@ -1,7 +1,6 @@
#if MULTIPLAYER_TOOLS
using System;
using System.Collections;
using System.IO;
using NUnit.Framework;
using Unity.Collections;
using Unity.Multiplayer.Tools.MetricTypes;
@@ -15,7 +14,7 @@ namespace Unity.Netcode.RuntimeTests.Metrics
{
// Header is dynamically sized due to packing, will be 2 bytes for all test messages.
private const int k_MessageHeaderSize = 2;
static readonly long MessageOverhead = 8 + FastBufferWriter.GetWriteSize<BatchHeader>() + k_MessageHeaderSize;
private static readonly long k_MessageOverhead = 8 + FastBufferWriter.GetWriteSize<BatchHeader>() + k_MessageHeaderSize;
[UnityTest]
public IEnumerator TrackTotalNumberOfBytesSent()
@@ -42,7 +41,7 @@ namespace Unity.Netcode.RuntimeTests.Metrics
}
Assert.True(observer.Found);
Assert.AreEqual(FastBufferWriter.GetWriteSize(messageName) + MessageOverhead, observer.Value);
Assert.AreEqual(FastBufferWriter.GetWriteSize(messageName) + k_MessageOverhead, observer.Value);
}
[UnityTest]
@@ -72,7 +71,7 @@ namespace Unity.Netcode.RuntimeTests.Metrics
}
Assert.True(observer.Found);
Assert.AreEqual(FastBufferWriter.GetWriteSize(messageName) + MessageOverhead, observer.Value);
Assert.AreEqual(FastBufferWriter.GetWriteSize(messageName) + k_MessageOverhead, observer.Value);
}
private class TotalBytesObserver : IMetricObserver