com.unity.netcode.gameobjects@1.5.1

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.5.1] - 2023-06-07

### Added

- Added support for serializing `NativeArray<>` and `NativeList<>` in `FastBufferReader`/`FastBufferWriter`, `BufferSerializer`, `NetworkVariable`, and RPCs. (To use `NativeList<>`, add `UNITY_NETCODE_NATIVE_COLLECTION_SUPPORT` to your Scripting Define Symbols in `Project Settings > Player`) (#2375)
- The location of the automatically-created default network prefab list can now be configured (#2544)
- Added: Message size limits (max single message and max fragmented message) can now be set using NetworkManager.MaximumTransmissionUnitSize and NetworkManager.MaximumFragmentedMessageSize for transports that don't work with the default values (#2530)
- Added `NetworkObject.SpawnWithObservers` property (default is true) that when set to false will spawn a `NetworkObject` with no observers and will not be spawned on any client until `NetworkObject.NetworkShow` is invoked. (#2568)

### Fixed

- Fixed: Fixed a null reference in codegen in some projects (#2581)
- Fixed issue where the `OnClientDisconnected` client identifier was incorrect after a pending client connection was denied. (#2569)
- Fixed warning "Runtime Network Prefabs was not empty at initialization time." being erroneously logged when no runtime network prefabs had been added (#2565)
- Fixed issue where some temporary debug console logging was left in a merged PR. (#2562)
- Fixed the "Generate Default Network Prefabs List" setting not loading correctly and always reverting to being checked. (#2545)
- Fixed issue where users could not use NetworkSceneManager.VerifySceneBeforeLoading to exclude runtime generated scenes from client synchronization. (#2550)
- Fixed missing value on `NetworkListEvent` for `EventType.RemoveAt` events.  (#2542,#2543)
- Fixed issue where parenting a NetworkTransform under a transform with a scale other than Vector3.one would result in incorrect values on non-authoritative instances. (#2538)
- Fixed issue where a server would include scene migrated and then despawned NetworkObjects to a client that was being synchronized. (#2532)
- Fixed the inspector throwing exceptions when attempting to render `NetworkVariable`s of enum types. (#2529)
- Making a `NetworkVariable` with an `INetworkSerializable` type that doesn't meet the `new()` constraint will now create a compile-time error instead of an editor crash (#2528)
- Fixed Multiplayer Tools package installation docs page link on the NetworkManager popup. (#2526)
- Fixed an exception and error logging when two different objects are shown and hidden on the same frame (#2524)
- Fixed a memory leak in `UnityTransport` that occurred if `StartClient` failed. (#2518)
- Fixed issue where a client could throw an exception if abruptly disconnected from a network session with one or more spawned `NetworkObject`(s). (#2510)
- Fixed issue where invalid endpoint addresses were not being detected and returning false from NGO UnityTransport. (#2496)
- Fixed some errors that could occur if a connection is lost and the loss is detected when attempting to write to the socket. (#2495)

## Changed

- Adding network prefabs before NetworkManager initialization is now supported. (#2565)
- Connecting clients being synchronized now switch to the server's active scene before spawning and synchronizing NetworkObjects. (#2532)
- Updated `UnityTransport` dependency on `com.unity.transport` to 1.3.4. (#2533)
- Improved performance of NetworkBehaviour initialization by replacing reflection when initializing NetworkVariables with compile-time code generation, which should help reduce hitching during additive scene loads. (#2522)
This commit is contained in:
Unity Technologies
2023-06-07 00:00:00 +00:00
parent b5abc3ff7c
commit 4d70c198bd
119 changed files with 11328 additions and 3164 deletions

View File

@@ -50,7 +50,7 @@ namespace Unity.Netcode
{
if (tickRate == 0)
{
throw new ArgumentException("Tickrate must be a positive value.", nameof(tickRate));
throw new ArgumentException("Tick rate must be a positive value.", nameof(tickRate));
}
TickRate = tickRate;

View File

@@ -1,4 +1,5 @@
using System;
using Unity.Profiling;
namespace Unity.Netcode
{
@@ -8,6 +9,34 @@ namespace Unity.Netcode
/// </summary>
public class NetworkTimeSystem
{
/// <summary>
/// TODO 2023-Q2: Not sure if this just needs to go away, but there is nothing that ever replaces this
/// </summary>
/// <remarks>
/// This was the original comment when it lived in NetworkManager:
/// todo talk with UX/Product, find good default value for this
/// </remarks>
private const float k_DefaultBufferSizeSec = 0.05f;
/// <summary>
/// Time synchronization frequency defaults to 1 synchronization message per second
/// </summary>
private const double k_TimeSyncFrequency = 1.0d;
/// <summary>
/// The threshold, in seconds, used to force a hard catchup of network time
/// </summary>
private const double k_HardResetThresholdSeconds = 0.2d;
/// <summary>
/// Default adjustment ratio
/// </summary>
private const double k_DefaultAdjustmentRatio = 0.01d;
#if DEVELOPMENT_BUILD || UNITY_EDITOR
private static ProfilerMarker s_SyncTime = new ProfilerMarker($"{nameof(NetworkManager)}.SyncTime");
#endif
private double m_TimeSec;
private double m_CurrentLocalTimeOffset;
private double m_DesiredLocalTimeOffset;
@@ -50,6 +79,16 @@ namespace Unity.Netcode
internal double LastSyncedServerTimeSec { get; private set; }
internal double LastSyncedRttSec { get; private set; }
private NetworkConnectionManager m_ConnectionManager;
private NetworkTransport m_NetworkTransport;
private NetworkTickSystem m_NetworkTickSystem;
private NetworkManager m_NetworkManager;
/// <summary>
/// <see cref="k_TimeSyncFrequency"/>
/// </summary>
private int m_TimeSyncFrequencyTicks;
/// <summary>
/// The constructor class for <see cref="NetworkTickSystem"/>
/// </summary>
@@ -57,7 +96,7 @@ namespace Unity.Netcode
/// <param name="serverBufferSec">The amount of the time in seconds the client should buffer incoming messages from the server.</param>
/// <param name="hardResetThresholdSec">The threshold, in seconds, used to force a hard catchup of network time.</param>
/// <param name="adjustmentRatio">The ratio at which the NetworkTimeSystem speeds up or slows down time.</param>
public NetworkTimeSystem(double localBufferSec, double serverBufferSec, double hardResetThresholdSec, double adjustmentRatio = 0.01d)
public NetworkTimeSystem(double localBufferSec, double serverBufferSec = k_DefaultBufferSizeSec, double hardResetThresholdSec = k_HardResetThresholdSeconds, double adjustmentRatio = k_DefaultAdjustmentRatio)
{
LocalBufferSec = localBufferSec;
ServerBufferSec = serverBufferSec;
@@ -65,6 +104,89 @@ namespace Unity.Netcode
AdjustmentRatio = adjustmentRatio;
}
/// <summary>
/// The primary time system is initialized when a server-host or client is started
/// </summary>
internal NetworkTickSystem Initialize(NetworkManager networkManager)
{
m_NetworkManager = networkManager;
m_ConnectionManager = networkManager.ConnectionManager;
m_NetworkTransport = networkManager.NetworkConfig.NetworkTransport;
m_TimeSyncFrequencyTicks = (int)(k_TimeSyncFrequency * networkManager.NetworkConfig.TickRate);
m_NetworkTickSystem = new NetworkTickSystem(networkManager.NetworkConfig.TickRate, 0, 0);
// Only the server side needs to register for tick based time synchronization
if (m_ConnectionManager.LocalClient.IsServer)
{
m_NetworkTickSystem.Tick += OnTickSyncTime;
}
return m_NetworkTickSystem;
}
internal void UpdateTime()
{
// As a client wait to run the time system until we are connected.
// As a client or server don't worry about the time system if we are no longer processing messages
if (!m_ConnectionManager.LocalClient.IsServer && !m_ConnectionManager.LocalClient.IsConnected)
{
return;
}
// Only update RTT here, server time is updated by time sync messages
var reset = Advance(m_NetworkManager.RealTimeProvider.UnscaledDeltaTime);
if (reset)
{
m_NetworkTickSystem.Reset(LocalTime, ServerTime);
}
m_NetworkTickSystem.UpdateTick(LocalTime, ServerTime);
if (!m_ConnectionManager.LocalClient.IsServer)
{
Sync(LastSyncedServerTimeSec + m_NetworkManager.RealTimeProvider.UnscaledDeltaTime, m_NetworkTransport.GetCurrentRtt(NetworkManager.ServerClientId) / 1000d);
}
}
/// <summary>
/// Server-Side:
/// Synchronizes time with clients based on the given <see cref="m_TimeSyncFrequencyTicks"/>.
/// Also: <see cref="k_TimeSyncFrequency"/>
/// </summary>
/// <remarks>
/// The default is to send 1 time synchronization message per second
/// </remarks>
private void OnTickSyncTime()
{
#if DEVELOPMENT_BUILD || UNITY_EDITOR
s_SyncTime.Begin();
#endif
// Check if we need to send a time synchronization message, and if so send it
if (m_ConnectionManager.LocalClient.IsServer && m_NetworkTickSystem.ServerTime.Tick % m_TimeSyncFrequencyTicks == 0)
{
var message = new TimeSyncMessage
{
Tick = m_NetworkTickSystem.ServerTime.Tick
};
m_ConnectionManager.SendMessage(ref message, NetworkDelivery.Unreliable, m_ConnectionManager.ConnectedClientIds);
}
#if DEVELOPMENT_BUILD || UNITY_EDITOR
s_SyncTime.End();
#endif
}
/// <summary>
/// Invoke when shutting down the NetworkManager
/// </summary>
internal void Shutdown()
{
if (m_ConnectionManager.LocalClient.IsServer)
{
m_NetworkTickSystem.Tick -= OnTickSyncTime;
}
}
/// <summary>
/// Creates a new instance of the <see cref="NetworkTimeSystem"/> class for a server instance.
/// The server will not apply any buffer values which ensures that local time equals server time.