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:
@@ -810,20 +810,27 @@ namespace Unity.Netcode
|
||||
networkObject.DontDestroyWithOwner = sceneObject.DontDestroyWithOwner;
|
||||
networkObject.Ownership = (NetworkObject.OwnershipStatus)sceneObject.OwnershipFlags;
|
||||
|
||||
|
||||
var nonNetworkObjectParent = false;
|
||||
// SPECIAL CASE FOR IN-SCENE PLACED: (only when the parent has a NetworkObject)
|
||||
// This is a special case scenario where a late joining client has joined and loaded one or
|
||||
// more scenes that contain nested in-scene placed NetworkObject children yet the server's
|
||||
// synchronization information does not indicate the NetworkObject in question has a parent.
|
||||
// Under this scenario, we want to remove the parent before spawning and setting the transform values.
|
||||
if (sceneObject.IsSceneObject && !sceneObject.HasParent && networkObject.transform.parent != null)
|
||||
if (sceneObject.IsSceneObject && networkObject.transform.parent != null)
|
||||
{
|
||||
var parentNetworkObject = networkObject.transform.parent.GetComponent<NetworkObject>();
|
||||
// if the in-scene placed NetworkObject has a parent NetworkObject but the synchronization information does not
|
||||
// include parenting, then we need to force the removal of that parent
|
||||
if (networkObject.transform.parent.GetComponent<NetworkObject>() != null)
|
||||
if (!sceneObject.HasParent && parentNetworkObject)
|
||||
{
|
||||
// remove the parent
|
||||
networkObject.ApplyNetworkParenting(true, true);
|
||||
}
|
||||
else if (sceneObject.HasParent && !parentNetworkObject)
|
||||
{
|
||||
nonNetworkObjectParent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the transform unless we were spawned by a prefab handler
|
||||
@@ -833,7 +840,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
// If world position stays is true or we have auto object parent synchronization disabled
|
||||
// then we want to apply the position and rotation values world space relative
|
||||
if (worldPositionStays || !networkObject.AutoObjectParentSync)
|
||||
if ((worldPositionStays && !nonNetworkObjectParent) || !networkObject.AutoObjectParentSync)
|
||||
{
|
||||
networkObject.transform.position = position;
|
||||
networkObject.transform.rotation = rotation;
|
||||
@@ -917,6 +924,8 @@ namespace Unity.Netcode
|
||||
Debug.LogError("Spawning NetworkObjects with nested NetworkObjects is only supported for scene objects. Child NetworkObjects will not be spawned over the network!");
|
||||
}
|
||||
}
|
||||
// Invoke NetworkBehaviour.OnPreSpawn methods
|
||||
networkObject.InvokeBehaviourNetworkPreSpawn();
|
||||
|
||||
// DANGO-TODO: It would be nice to allow users to specify which clients are observers prior to spawning
|
||||
// For now, this is the best place I could find to add all connected clients as observers for newly
|
||||
@@ -957,12 +966,18 @@ namespace Unity.Netcode
|
||||
}
|
||||
}
|
||||
SpawnNetworkObjectLocallyCommon(networkObject, networkId, sceneObject, playerObject, ownerClientId, destroyWithScene);
|
||||
|
||||
// Invoke NetworkBehaviour.OnPostSpawn methods
|
||||
networkObject.InvokeBehaviourNetworkPostSpawn();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is only invoked to instantiate a serialized NetworkObject via
|
||||
/// <see cref="NetworkObject.AddSceneObject(in NetworkObject.SceneObject, FastBufferReader, NetworkManager, bool)"/>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// IMPORTANT: Pre spawn methods need to be invoked from within <see cref="NetworkObject.AddSceneObject"/>.
|
||||
/// </remarks>
|
||||
internal void SpawnNetworkObjectLocally(NetworkObject networkObject, in NetworkObject.SceneObject sceneObject, bool destroyWithScene)
|
||||
{
|
||||
if (networkObject == null)
|
||||
@@ -975,7 +990,11 @@ namespace Unity.Netcode
|
||||
throw new SpawnStateException($"[{networkObject.name}] Object-{networkObject.NetworkObjectId} is already spawned!");
|
||||
}
|
||||
|
||||
// Do not invoke Pre spawn here (SynchronizeNetworkBehaviours needs to be invoked prior to this)
|
||||
SpawnNetworkObjectLocallyCommon(networkObject, sceneObject.NetworkObjectId, sceneObject.IsSceneObject, sceneObject.IsPlayerObject, sceneObject.OwnerClientId, destroyWithScene);
|
||||
|
||||
// It is ok to invoke NetworkBehaviour.OnPostSpawn methods
|
||||
networkObject.InvokeBehaviourNetworkPostSpawn();
|
||||
}
|
||||
|
||||
private void SpawnNetworkObjectLocallyCommon(NetworkObject networkObject, ulong networkId, bool sceneObject, bool playerObject, ulong ownerClientId, bool destroyWithScene)
|
||||
@@ -1226,7 +1245,7 @@ namespace Unity.Netcode
|
||||
{
|
||||
// If it is an in-scene placed NetworkObject then just despawn and let it be destroyed when the scene
|
||||
// is unloaded. Otherwise, despawn and destroy it.
|
||||
var shouldDestroy = !(networkObjects[i].IsSceneObject != null && networkObjects[i].IsSceneObject.Value);
|
||||
var shouldDestroy = !(networkObjects[i].IsSceneObject == null || (networkObjects[i].IsSceneObject != null && networkObjects[i].IsSceneObject.Value));
|
||||
|
||||
// If we are going to destroy this NetworkObject, check for any in-scene placed children that need to be removed
|
||||
if (shouldDestroy)
|
||||
@@ -1307,6 +1326,7 @@ namespace Unity.Netcode
|
||||
var networkObjects = UnityEngine.Object.FindObjectsOfType<NetworkObject>();
|
||||
#endif
|
||||
var isConnectedCMBService = NetworkManager.CMBServiceConnection;
|
||||
var networkObjectsToSpawn = new List<NetworkObject>();
|
||||
for (int i = 0; i < networkObjects.Length; i++)
|
||||
{
|
||||
if (networkObjects[i].NetworkManager == NetworkManager)
|
||||
@@ -1323,9 +1343,17 @@ namespace Unity.Netcode
|
||||
}
|
||||
|
||||
SpawnNetworkObjectLocally(networkObjects[i], GetNetworkObjectId(), true, false, ownerId, true);
|
||||
networkObjectsToSpawn.Add(networkObjects[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Notify all in-scene placed NetworkObjects have been spawned
|
||||
foreach (var networkObject in networkObjectsToSpawn)
|
||||
{
|
||||
networkObject.InternalInSceneNetworkObjectsSpawned();
|
||||
}
|
||||
networkObjectsToSpawn.Clear();
|
||||
}
|
||||
|
||||
internal void OnDespawnObject(NetworkObject networkObject, bool destroyGameObject, bool modeDestroy = false)
|
||||
|
||||
Reference in New Issue
Block a user