com.unity.netcode.gameobjects@2.0.0-exp.4
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). ## [2.0.0-exp.4] - 2024-05-31 ### Added - Added `NetworkRigidbodyBase.AttachToFixedJoint` and `NetworkRigidbodyBase.DetachFromFixedJoint` to replace parenting for rigid bodies that have `NetworkRigidbodyBase.UseRigidBodyForMotion` enabled. (#2933) - Added `NetworkBehaviour.OnNetworkPreSpawn` and `NetworkBehaviour.OnNetworkPostSpawn` methods that provide the ability to handle pre and post spawning actions during the `NetworkObject` spawn sequence. (#2912) - Added a client-side only `NetworkBehaviour.OnNetworkSessionSynchronized` convenience method that is invoked on all `NetworkBehaviour`s after a newly joined client has finished synchronizing with the network session in progress. (#2912) - Added `NetworkBehaviour.OnInSceneObjectsSpawned` convenience method that is invoked when all in-scene `NetworkObject`s have been spawned after a scene has been loaded or upon a host or server starting. (#2912) ### Fixed - Fixed issue where non-authoritative rigid bodies with `NetworkRigidbodyBase.UseRigidBodyForMotion` enabled would constantly log errors about the renderTime being before `StartTimeConsumed`. (#2933) - Fixed issue where in-scene placed NetworkObjects could be destroyed if a client disconnects early and/or before approval. (#2924) - Fixed issue where a `NetworkObject` component's associated `NetworkBehaviour` components would not be detected if scene loading is disabled in the editor and the currently loaded scene has in-scene placed `NetworkObject`s. (#2912) - Fixed issue where an in-scene placed `NetworkObject` with `NetworkTransform` that is also parented under a `GameObject` would not properly synchronize when the parent `GameObject` had a world space position other than 0,0,0. (#2898) ### Changed - Change all the access modifiers of test class from Public to Internal (#2930) - Changed messages are now sorted by enum values as opposed to ordinally sorting the messages by their type name. (#2929) - Changed `NetworkClient.SessionModeTypes` to `NetworkClient.NetworkTopologyTypes`. (#2875) - Changed `NetworkClient.SessionModeType` to `NetworkClient.NetworkTopologyType`. (#2875) - Changed `NetworkConfig.SessionMode` to `NeworkConfig.NetworkTopology`. (#2875)
This commit is contained in:
@@ -425,7 +425,7 @@ namespace Unity.Netcode
|
||||
|
||||
/// <summary>
|
||||
/// Returns the currently loaded scenes that are synchronized with the session owner or server depending upon the selected
|
||||
/// NetworkManager session mode.
|
||||
/// network topology.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The <see cref="SceneManager"/> scenes loaded returns all scenes loaded where this returns only the scenes that have been
|
||||
@@ -444,6 +444,7 @@ namespace Unity.Netcode
|
||||
internal Dictionary<int, int> ServerSceneHandleToClientSceneHandle = new Dictionary<int, int>();
|
||||
internal Dictionary<int, int> ClientSceneHandleToServerSceneHandle = new Dictionary<int, int>();
|
||||
|
||||
internal bool IsRestoringSession;
|
||||
/// <summary>
|
||||
/// Add the client to server (and vice versa) scene handle lookup.
|
||||
/// Add the client-side handle to scene entry in the HandleToScene table.
|
||||
@@ -455,7 +456,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
ServerSceneHandleToClientSceneHandle.Add(serverHandle, clientHandle);
|
||||
}
|
||||
else
|
||||
else if (!IsRestoringSession)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -464,7 +465,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
ClientSceneHandleToServerSceneHandle.Add(clientHandle, serverHandle);
|
||||
}
|
||||
else
|
||||
else if (!IsRestoringSession)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -1045,7 +1046,7 @@ namespace Unity.Netcode
|
||||
/// <param name="targetClientIds">array of client identifiers to receive the scene event message</param>
|
||||
private void SendSceneEventData(uint sceneEventId, ulong[] targetClientIds)
|
||||
{
|
||||
if (targetClientIds.Length == 0)
|
||||
if (targetClientIds.Length == 0 && !NetworkManager.DistributedAuthorityMode)
|
||||
{
|
||||
// This would be the Host/Server with no clients connected
|
||||
// Silently return as there is nothing to be done
|
||||
@@ -1056,6 +1057,16 @@ namespace Unity.Netcode
|
||||
|
||||
if (NetworkManager.DistributedAuthorityMode && !NetworkManager.DAHost)
|
||||
{
|
||||
if (NetworkManager.DistributedAuthorityMode && HasSceneAuthority())
|
||||
{
|
||||
sceneEvent.TargetClientId = NetworkManager.ServerClientId;
|
||||
var message = new SceneEventMessage
|
||||
{
|
||||
EventData = sceneEvent,
|
||||
};
|
||||
var size = NetworkManager.ConnectionManager.SendMessage(ref message, k_DeliveryType, NetworkManager.ServerClientId);
|
||||
NetworkManager.NetworkMetrics.TrackSceneEventSent(NetworkManager.ServerClientId, (uint)sceneEvent.SceneEventType, SceneNameFromHash(sceneEvent.SceneHash), size);
|
||||
}
|
||||
foreach (var clientId in targetClientIds)
|
||||
{
|
||||
sceneEvent.TargetClientId = clientId;
|
||||
@@ -1859,6 +1870,17 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var keyValuePairByGlobalObjectIdHash in ScenePlacedObjects)
|
||||
{
|
||||
foreach (var keyValuePairBySceneHandle in keyValuePairByGlobalObjectIdHash.Value)
|
||||
{
|
||||
if (!keyValuePairBySceneHandle.Value.IsPlayerObject)
|
||||
{
|
||||
keyValuePairBySceneHandle.Value.InternalInSceneNetworkObjectsSpawned();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add any despawned when spawned in-scene placed NetworkObjects to the scene event data
|
||||
sceneEventData.AddDespawnedInSceneNetworkObjects();
|
||||
|
||||
@@ -2413,6 +2435,18 @@ namespace Unity.Netcode
|
||||
{
|
||||
NetworkLog.LogInfo($"[Client-{NetworkManager.LocalClientId}][Scene Management Enabled] Synchronization complete!");
|
||||
}
|
||||
// For convenience, notify all NetworkBehaviours that synchronization is complete.
|
||||
foreach (var networkObject in NetworkManager.SpawnManager.SpawnedObjectsList)
|
||||
{
|
||||
networkObject.InternalNetworkSessionSynchronized();
|
||||
}
|
||||
|
||||
if (NetworkManager.DistributedAuthorityMode && HasSceneAuthority() && IsRestoringSession)
|
||||
{
|
||||
IsRestoringSession = false;
|
||||
PostSynchronizationSceneUnloading = m_OriginalPostSynchronizationSceneUnloading;
|
||||
}
|
||||
|
||||
EndSceneEvent(sceneEventId);
|
||||
}
|
||||
break;
|
||||
@@ -2599,6 +2633,8 @@ namespace Unity.Netcode
|
||||
/// </summary>
|
||||
internal bool SkipSceneHandling;
|
||||
|
||||
private bool m_OriginalPostSynchronizationSceneUnloading;
|
||||
|
||||
/// <summary>
|
||||
/// Both Client and Server: Incoming scene event entry point
|
||||
/// </summary>
|
||||
@@ -2672,6 +2708,12 @@ namespace Unity.Netcode
|
||||
// Only if ClientSynchronizationMode is Additive and the client receives a synchronize scene event
|
||||
if (ClientSynchronizationMode == LoadSceneMode.Additive)
|
||||
{
|
||||
if (NetworkManager.DistributedAuthorityMode && HasSceneAuthority() && IsRestoringSession && clientId == NetworkManager.ServerClientId)
|
||||
{
|
||||
m_OriginalPostSynchronizationSceneUnloading = PostSynchronizationSceneUnloading;
|
||||
PostSynchronizationSceneUnloading = true;
|
||||
}
|
||||
|
||||
// Check for scenes already loaded and create a table of scenes already loaded (SceneEntries) that will be
|
||||
// used if the server is synchronizing the same scenes (i.e. if a matching scene is already loaded on the
|
||||
// client side, then that scene will be used as opposed to loading another scene). This allows for clients
|
||||
|
||||
@@ -839,7 +839,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
// is not packed!
|
||||
InternalBuffer.ReadValueSafe(out ushort newObjectsCount);
|
||||
|
||||
var sceneObjects = new List<NetworkObject>();
|
||||
for (ushort i = 0; i < newObjectsCount; i++)
|
||||
{
|
||||
var sceneObject = new NetworkObject.SceneObject();
|
||||
@@ -851,10 +851,22 @@ namespace Unity.Netcode
|
||||
m_NetworkManager.SceneManager.SetTheSceneBeingSynchronized(sceneObject.NetworkSceneHandle);
|
||||
}
|
||||
|
||||
NetworkObject.AddSceneObject(sceneObject, InternalBuffer, m_NetworkManager);
|
||||
var networkObject = NetworkObject.AddSceneObject(sceneObject, InternalBuffer, m_NetworkManager);
|
||||
|
||||
if (sceneObject.IsSceneObject)
|
||||
{
|
||||
sceneObjects.Add(networkObject);
|
||||
}
|
||||
}
|
||||
// Now deserialize the despawned in-scene placed NetworkObjects list (if any)
|
||||
DeserializeDespawnedInScenePlacedNetworkObjects();
|
||||
|
||||
// Notify all newly spawned in-scene placed NetworkObjects that all in-scene placed
|
||||
// NetworkObjects have been spawned.
|
||||
foreach (var networkObject in sceneObjects)
|
||||
{
|
||||
networkObject.InternalInSceneNetworkObjectsSpawned();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -1122,6 +1134,15 @@ namespace Unity.Netcode
|
||||
UnityEngine.Debug.Log(builder.ToString());
|
||||
}
|
||||
|
||||
// Notify that all in-scene placed NetworkObjects have been spawned
|
||||
foreach (var networkObject in m_NetworkObjectsSync)
|
||||
{
|
||||
if (networkObject.IsSceneObject.HasValue && networkObject.IsSceneObject.Value)
|
||||
{
|
||||
networkObject.InternalInSceneNetworkObjectsSpawned();
|
||||
}
|
||||
}
|
||||
|
||||
// Now deserialize the despawned in-scene placed NetworkObjects list (if any)
|
||||
DeserializeDespawnedInScenePlacedNetworkObjects();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user