com.unity.netcode.gameobjects@1.8.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.8.0] - 2023-12-12 ### Added - Added a new RPC attribute, which is simply `Rpc`. (#2762) - This is a generic attribute that can perform the functions of both Server and Client RPCs, as well as enabling client-to-client RPCs. Includes several default targets: `Server`, `NotServer`, `Owner`, `NotOwner`, `Me`, `NotMe`, `ClientsAndHost`, and `Everyone`. Runtime overrides are available for any of these targets, as well as for sending to a specific ID or groups of IDs. - This attribute also includes the ability to defer RPCs that are sent to the local process to the start of the next frame instead of executing them immediately, treating them as if they had gone across the network. The default behavior is to execute immediately. - This attribute effectively replaces `ServerRpc` and `ClientRpc`. `ServerRpc` and `ClientRpc` remain in their existing forms for backward compatibility, but `Rpc` will be the recommended and most supported option. - Added `NetworkManager.OnConnectionEvent` as a unified connection event callback to notify clients and servers of all client connections and disconnections within the session (#2762) - Added `NetworkManager.ServerIsHost` and `NetworkBehaviour.ServerIsHost` to allow a client to tell if it is connected to a host or to a dedicated server (#2762) - Added `SceneEventProgress.SceneManagementNotEnabled` return status to be returned when a `NetworkSceneManager` method is invoked and scene management is not enabled. (#2735) - Added `SceneEventProgress.ServerOnlyAction` return status to be returned when a `NetworkSceneManager` method is invoked by a client. (#2735) - Added `NetworkObject.InstantiateAndSpawn` and `NetworkSpawnManager.InstantiateAndSpawn` methods to simplify prefab spawning by assuring that the prefab is valid and applies any override prior to instantiating the `GameObject` and spawning the `NetworkObject` instance. (#2710) ### Fixed - Fixed issue where a client disconnected by a server-host would not receive a local notification. (#2789) - Fixed issue where a server-host could shutdown during a relay connection but periodically the transport disconnect message sent to any connected clients could be dropped. (#2789) - Fixed issue where a host could disconnect its local client but remain running as a server. (#2789) - Fixed issue where `OnClientDisconnectedCallback` was not being invoked under certain conditions. (#2789) - Fixed issue where `OnClientDisconnectedCallback` was always returning 0 as the client identifier. (#2789) - Fixed issue where if a host or server shutdown while a client owned NetworkObjects (other than the player) it would throw an exception. (#2789) - Fixed issue where setting values on a `NetworkVariable` or `NetworkList` within `OnNetworkDespawn` during a shutdown sequence would throw an exception. (#2789) - Fixed issue where a teleport state could potentially be overridden by a previous unreliable delta state. (#2777) - Fixed issue where `NetworkTransform` was using the `NetworkManager.ServerTime.Tick` as opposed to `NetworkManager.NetworkTickSystem.ServerTime.Tick` during the authoritative side's tick update where it performed a delta state check. (#2777) - Fixed issue where a parented in-scene placed NetworkObject would be destroyed upon a client or server exiting a network session but not unloading the original scene in which the NetworkObject was placed. (#2737) - Fixed issue where during client synchronization and scene loading, when client synchronization or the scene loading mode are set to `LoadSceneMode.Single`, a `CreateObjectMessage` could be received, processed, and the resultant spawned `NetworkObject` could be instantiated in the client's currently active scene that could, towards the end of the client synchronization or loading process, be unloaded and cause the newly created `NetworkObject` to be destroyed (and throw and exception). (#2735) - Fixed issue where a `NetworkTransform` instance with interpolation enabled would result in wide visual motion gaps (stuttering) under above normal latency conditions and a 1-5% or higher packet are drop rate. (#2713) - Fixed issue where you could not have multiple source network prefab overrides targeting the same network prefab as their override. (#2710) ### Changed - Changed the server or host shutdown so it will now perform a "soft shutdown" when `NetworkManager.Shutdown` is invoked. This will send a disconnect notification to all connected clients and the server-host will wait for all connected clients to disconnect or timeout after a 5 second period before completing the shutdown process. (#2789) - Changed `OnClientDisconnectedCallback` will now return the assigned client identifier on the local client side if the client was approved and assigned one prior to being disconnected. (#2789) - Changed `NetworkTransform.SetState` (and related methods) now are cumulative during a fractional tick period and sent on the next pending tick. (#2777) - `NetworkManager.ConnectedClientsIds` is now accessible on the client side and will contain the list of all clients in the session, including the host client if the server is operating in host mode (#2762) - Changed `NetworkSceneManager` to return a `SceneEventProgress` status and not throw exceptions for methods invoked when scene management is disabled and when a client attempts to access a `NetworkSceneManager` method by a client. (#2735) - Changed `NetworkTransform` authoritative instance tick registration so a single `NetworkTransform` specific tick event update will update all authoritative instances to improve perofmance. (#2713) - Changed `NetworkPrefabs.OverrideToNetworkPrefab` dictionary is no longer used/populated due to it ending up being related to a regression bug and not allowing more than one override to be assigned to a network prefab asset. (#2710) - Changed in-scene placed `NetworkObject`s now store their source network prefab asset's `GlobalObjectIdHash` internally that is used, when scene management is disabled, by clients to spawn the correct prefab even if the `NetworkPrefab` entry has an override. This does not impact dynamically spawning the same prefab which will yield the override on both host and client. (#2710) - Changed in-scene placed `NetworkObject`s no longer require a `NetworkPrefab` entry with `GlobalObjectIdHash` override in order for clients to properly synchronize. (#2710) - Changed in-scene placed `NetworkObject`s now set their `IsSceneObject` value when generating their `GlobalObjectIdHash` value. (#2710) - Changed the default `NetworkConfig.SpawnTimeout` value from 1.0s to 10.0s. (#2710)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
@@ -597,6 +598,47 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used for integration tests, normal runtime mode this will always be LoadSceneMode.Single
|
||||
/// </summary>
|
||||
internal LoadSceneMode DeferLoadingFilter = LoadSceneMode.Single;
|
||||
/// <summary>
|
||||
/// Determines if a remote client should defer object creation initiated by CreateObjectMessage
|
||||
/// until a scene event is completed.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Deferring object creation should only occur when there is a possibility the objects could be
|
||||
/// instantiated in a currently active scene that will be unloaded during single mode scene loading
|
||||
/// to prevent the newly created objects from being destroyed when the scene is unloaded.
|
||||
/// </remarks>
|
||||
internal bool ShouldDeferCreateObject()
|
||||
{
|
||||
// This applies only to remote clients and when scene management is enabled
|
||||
if (!NetworkManager.NetworkConfig.EnableSceneManagement || NetworkManager.IsServer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var synchronizeEventDetected = false;
|
||||
var loadingEventDetected = false;
|
||||
foreach (var entry in SceneEventDataStore)
|
||||
{
|
||||
if (entry.Value.SceneEventType == SceneEventType.Synchronize)
|
||||
{
|
||||
synchronizeEventDetected = true;
|
||||
}
|
||||
|
||||
// When loading a scene and the load scene mode is single we should defer object creation
|
||||
if (entry.Value.SceneEventType == SceneEventType.Load && entry.Value.LoadSceneMode == DeferLoadingFilter)
|
||||
{
|
||||
loadingEventDetected = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Synchronizing while in client synchronization mode single --> Defer
|
||||
// When not synchronizing but loading a scene in single mode --> Defer
|
||||
return (synchronizeEventDetected && ClientSynchronizationMode == LoadSceneMode.Single) || (!synchronizeEventDetected && loadingEventDetected);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scene name from full path to the scene
|
||||
/// </summary>
|
||||
@@ -740,12 +782,17 @@ namespace Unity.Netcode
|
||||
// Since NetworkManager is now always migrated to the DDOL we will use this to get the DDOL scene
|
||||
DontDestroyOnLoadScene = networkManager.gameObject.scene;
|
||||
|
||||
// Since the server tracks loaded scenes, we need to add the currently active scene
|
||||
// to the list of scenes that can be unloaded.
|
||||
if (networkManager.IsServer)
|
||||
// Since the server tracks loaded scenes, we need to add any currently loaded scenes on the
|
||||
// server side when the NetworkManager is started and NetworkSceneManager instantiated when
|
||||
// scene management is enabled.
|
||||
if (networkManager.IsServer && networkManager.NetworkConfig.EnableSceneManagement)
|
||||
{
|
||||
var activeScene = SceneManager.GetActiveScene();
|
||||
ScenesLoaded.Add(activeScene.handle, activeScene);
|
||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
{
|
||||
var loadedScene = SceneManager.GetSceneAt(i);
|
||||
ScenesLoaded.Add(loadedScene.handle, loadedScene);
|
||||
}
|
||||
SceneManagerHandler.PopulateLoadedScenes(ref ScenesLoaded, NetworkManager);
|
||||
}
|
||||
|
||||
// Add to the server to client scene handle table
|
||||
@@ -969,17 +1016,16 @@ namespace Unity.Netcode
|
||||
/// <returns></returns>
|
||||
private SceneEventProgress ValidateSceneEventUnloading(Scene scene)
|
||||
{
|
||||
if (!NetworkManager.IsServer)
|
||||
{
|
||||
throw new NotServerException("Only server can start a scene event!");
|
||||
}
|
||||
|
||||
if (!NetworkManager.NetworkConfig.EnableSceneManagement)
|
||||
{
|
||||
//Log message about enabling SceneManagement
|
||||
throw new Exception(
|
||||
$"{nameof(NetworkConfig.EnableSceneManagement)} flag is not enabled in the {nameof(Netcode.NetworkManager)}'s {nameof(NetworkConfig)}. " +
|
||||
$"Please set {nameof(NetworkConfig.EnableSceneManagement)} flag to true before calling {nameof(LoadScene)} or {nameof(UnloadScene)}.");
|
||||
Debug.LogWarning($"{nameof(LoadScene)} was called, but {nameof(NetworkConfig.EnableSceneManagement)} was not enabled! Enable {nameof(NetworkConfig.EnableSceneManagement)} prior to starting a client, host, or server prior to using {nameof(NetworkSceneManager)}!");
|
||||
return new SceneEventProgress(null, SceneEventProgressStatus.SceneManagementNotEnabled);
|
||||
}
|
||||
|
||||
if (!NetworkManager.IsServer)
|
||||
{
|
||||
Debug.LogWarning($"[{nameof(SceneEventProgressStatus.ServerOnlyAction)}][Unload] Clients cannot invoke the {nameof(UnloadScene)} method!");
|
||||
return new SceneEventProgress(null, SceneEventProgressStatus.ServerOnlyAction);
|
||||
}
|
||||
|
||||
if (!scene.isLoaded)
|
||||
@@ -998,16 +1044,16 @@ namespace Unity.Netcode
|
||||
/// <returns></returns>
|
||||
private SceneEventProgress ValidateSceneEventLoading(string sceneName)
|
||||
{
|
||||
if (!NetworkManager.IsServer)
|
||||
{
|
||||
throw new NotServerException("Only server can start a scene event!");
|
||||
}
|
||||
if (!NetworkManager.NetworkConfig.EnableSceneManagement)
|
||||
{
|
||||
//Log message about enabling SceneManagement
|
||||
throw new Exception(
|
||||
$"{nameof(NetworkConfig.EnableSceneManagement)} flag is not enabled in the {nameof(Netcode.NetworkManager)}'s {nameof(NetworkConfig)}. " +
|
||||
$"Please set {nameof(NetworkConfig.EnableSceneManagement)} flag to true before calling {nameof(LoadScene)} or {nameof(UnloadScene)}.");
|
||||
Debug.LogWarning($"{nameof(LoadScene)} was called, but {nameof(NetworkConfig.EnableSceneManagement)} was not enabled! Enable {nameof(NetworkConfig.EnableSceneManagement)} prior to starting a client, host, or server prior to using {nameof(NetworkSceneManager)}!");
|
||||
return new SceneEventProgress(null, SceneEventProgressStatus.SceneManagementNotEnabled);
|
||||
}
|
||||
|
||||
if (!NetworkManager.IsServer)
|
||||
{
|
||||
Debug.LogWarning($"[{nameof(SceneEventProgressStatus.ServerOnlyAction)}][Load] Clients cannot invoke the {nameof(LoadScene)} method!");
|
||||
return new SceneEventProgress(null, SceneEventProgressStatus.ServerOnlyAction);
|
||||
}
|
||||
|
||||
return ValidateSceneEvent(sceneName);
|
||||
@@ -1112,6 +1158,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
var sceneName = scene.name;
|
||||
var sceneHandle = scene.handle;
|
||||
|
||||
if (!scene.isLoaded)
|
||||
{
|
||||
Debug.LogWarning($"{nameof(UnloadScene)} was called, but the scene {scene.name} is not currently loaded!");
|
||||
@@ -1697,6 +1744,9 @@ namespace Unity.Netcode
|
||||
SendSceneEventData(sceneEventId, new ulong[] { NetworkManager.ServerClientId });
|
||||
m_IsSceneEventActive = false;
|
||||
|
||||
// Process any pending create object messages that the client received while loading a scene
|
||||
ProcessDeferredCreateObjectMessages();
|
||||
|
||||
// Notify local client that the scene was loaded
|
||||
OnSceneEvent?.Invoke(new SceneEvent()
|
||||
{
|
||||
@@ -2058,6 +2108,9 @@ namespace Unity.Netcode
|
||||
// If needed, migrate dynamically spawned NetworkObjects to the same scene as they are on the server
|
||||
SynchronizeNetworkObjectScene();
|
||||
|
||||
// Process any pending create object messages that the client received during synchronization
|
||||
ProcessDeferredCreateObjectMessages();
|
||||
|
||||
sceneEventData.SceneEventType = SceneEventType.SynchronizeComplete;
|
||||
SendSceneEventData(sceneEventId, new ulong[] { NetworkManager.ServerClientId });
|
||||
|
||||
@@ -2213,6 +2266,11 @@ namespace Unity.Netcode
|
||||
// of the client was persisted since MLAPI)
|
||||
NetworkManager.ConnectionManager.InvokeOnClientConnectedCallback(clientId);
|
||||
|
||||
if (NetworkManager.IsHost)
|
||||
{
|
||||
NetworkManager.ConnectionManager.InvokeOnPeerConnectedCallback(clientId);
|
||||
}
|
||||
|
||||
// Check to see if the client needs to resynchronize and before sending the message make sure the client is still connected to avoid
|
||||
// a potential crash within the MessageSystem (i.e. sending to a client that no longer exists)
|
||||
if (sceneEventData.ClientNeedsReSynchronization() && !DisableReSynchronization && NetworkManager.ConnectedClients.ContainsKey(clientId))
|
||||
@@ -2549,5 +2607,50 @@ namespace Unity.Netcode
|
||||
internal Dictionary<int, List<ulong>> ObjectsMigratedTable;
|
||||
}
|
||||
internal List<DeferredObjectsMovedEvent> DeferredObjectsMovedEvents = new List<DeferredObjectsMovedEvent>();
|
||||
|
||||
internal struct DeferredObjectCreation
|
||||
{
|
||||
internal ulong SenderId;
|
||||
internal uint MessageSize;
|
||||
internal NetworkObject.SceneObject SceneObject;
|
||||
internal FastBufferReader FastBufferReader;
|
||||
}
|
||||
|
||||
internal List<DeferredObjectCreation> DeferredObjectCreationList = new List<DeferredObjectCreation>();
|
||||
internal int DeferredObjectCreationCount;
|
||||
|
||||
internal void DeferCreateObject(ulong senderId, uint messageSize, NetworkObject.SceneObject sceneObject, FastBufferReader fastBufferReader)
|
||||
{
|
||||
var deferredObjectCreationEntry = new DeferredObjectCreation()
|
||||
{
|
||||
SenderId = senderId,
|
||||
MessageSize = messageSize,
|
||||
SceneObject = sceneObject,
|
||||
};
|
||||
|
||||
unsafe
|
||||
{
|
||||
deferredObjectCreationEntry.FastBufferReader = new FastBufferReader(fastBufferReader.GetUnsafePtrAtCurrentPosition(), Allocator.Persistent, fastBufferReader.Length - fastBufferReader.Position);
|
||||
}
|
||||
|
||||
DeferredObjectCreationList.Add(deferredObjectCreationEntry);
|
||||
}
|
||||
|
||||
private void ProcessDeferredCreateObjectMessages()
|
||||
{
|
||||
// If no pending create object messages exit early
|
||||
if (DeferredObjectCreationList.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var networkManager = NetworkManager;
|
||||
// Process all deferred create object messages.
|
||||
foreach (var deferredObjectCreation in DeferredObjectCreationList)
|
||||
{
|
||||
CreateObjectMessage.CreateObject(ref networkManager, deferredObjectCreation.SenderId, deferredObjectCreation.MessageSize, deferredObjectCreation.SceneObject, deferredObjectCreation.FastBufferReader);
|
||||
}
|
||||
DeferredObjectCreationCount = DeferredObjectCreationList.Count;
|
||||
DeferredObjectCreationList.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,14 @@ namespace Unity.Netcode
|
||||
/// If you receive this event then it is most likely due to a bug (<em>please open a GitHub issue with steps to replicate</em>).<br/>
|
||||
/// </summary>
|
||||
InternalNetcodeError,
|
||||
/// <summary>
|
||||
/// This is returned when an unload or load action is attempted and scene management is disabled
|
||||
/// </summary>
|
||||
SceneManagementNotEnabled,
|
||||
/// <summary>
|
||||
/// This is returned when a client attempts to perform a server only action
|
||||
/// </summary>
|
||||
ServerOnlyAction,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user