com.unity.netcode.gameobjects@2.2.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). ## [2.2.0] - 2024-12-12 ### Added - Added `NetworkObject.OwnershipStatus.SessionOwner` to allow Network Objects to be distributable and only owned by the Session Owner. This flag will override all other `OwnershipStatus` flags. (#3175) - Added `UnityTransport.GetEndpoint` method to provide a way to obtain `NetworkEndpoint` information of a connection via client identifier. (#3130) - Added `NetworkTransport.OnEarlyUpdate` and `NetworkTransport.OnPostLateUpdate` methods to provide more control over handling transport related events at the start and end of each frame. (#3113) ### Fixed - Fixed issue where the server, host, or session owner would not populate the in-scene place `NetworkObject` table if the scene was loaded prior to starting the `NetworkManager`. (#3177) - Fixed issue where the `NetworkObjectIdHash` value could be incorrect when entering play mode while still in prefab edit mode with pending changes and using MPPM. (#3162) - Fixed issue where a sever only `NetworkManager` instance would spawn the actual `NetworkPrefab`'s `GameObject` as opposed to creating an instance of it. (#3160) - Fixed issue where only the session owner (as opposed to all clients) would handle spawning prefab overrides properly when using a distributed authority network topology. (#3160) - Fixed issue where an exception was thrown when calling `NetworkManager.Shutdown` after calling `UnityTransport.Shutdown`. (#3118) - Fixed issue where `NetworkList` properties on in-scene placed `NetworkObject`s could cause small memory leaks when entering playmode. (#3147) - Fixed in-scene `NertworkObject` synchronization issue when loading a scene with currently connected clients connected to a session created by a `NetworkManager` started as a server (i.e. not as a host). (#3133) - Fixed issue where a `NetworkManager` started as a server would not add itself as an observer to in-scene placed `NetworkObject`s instantiated and spawned by a scene loading event. (#3133) - Fixed issue where spawning a player using `NetworkObject.InstantiateAndSpawn` or `NetworkSpawnManager.InstantiateAndSpawn` would not update the `NetworkSpawnManager.PlayerObjects` or assign the newly spawned player to the `NetworkClient.PlayerObject`. (#3122) - Fixed issue where queued UnitTransport (NetworkTransport) message batches were being sent on the next frame. They are now sent at the end of the frame during `PostLateUpdate`. (#3113) - Fixed issue where `NotOwnerRpcTarget` or `OwnerRpcTarget` were not using their replacements `NotAuthorityRpcTarget` and `AuthorityRpcTarget` which would invoke a warning. (#3111) - Fixed issue where client is removed as an observer from spawned objects when their player instance is despawned. (#3110) - Fixed issue where `NetworkAnimator` would statically allocate write buffer space for `Animator` parameters that could cause a write error if the number of parameters exceeded the space allocated. (#3108) ### Changed - In-scene placed `NetworkObject`s have been made distributable when balancing object distribution after a connection event. (#3175) - Optimised `NetworkVariable` and `NetworkTransform` related packets when in Distributed Authority mode. - The Debug Simulator section of the Unity Transport component was removed. This section was not functional anymore and users are now recommended to use the more featureful [Network Simulator](https://docs-multiplayer.unity3d.com/tools/current/tools-network-simulator/) tool from the Multiplayer Tools package instead. (#3121)
This commit is contained in:
@@ -36,13 +36,25 @@ namespace Unity.Netcode.RuntimeTests
|
||||
{
|
||||
VerifyObjectIsSpawnedOnClient.ResetObjectTable();
|
||||
m_ClientNetworkTransformPrefab = CreateNetworkObjectPrefab("OwnerAuthorityTest");
|
||||
var clientNetworkObject = m_ClientNetworkTransformPrefab.GetComponent<NetworkObject>();
|
||||
// When running in distributed authority mode, make the NetworkObject transferable
|
||||
clientNetworkObject.SetOwnershipStatus(m_DistributedAuthority ? NetworkObject.OwnershipStatus.Transferable : NetworkObject.OwnershipStatus.None);
|
||||
var clientNetworkTransform = m_ClientNetworkTransformPrefab.AddComponent<TestClientNetworkTransform>();
|
||||
clientNetworkTransform.AuthorityMode = NetworkTransform.AuthorityModes.Owner;
|
||||
clientNetworkTransform.Interpolate = false;
|
||||
clientNetworkTransform.UseHalfFloatPrecision = false;
|
||||
var rigidBody = m_ClientNetworkTransformPrefab.AddComponent<Rigidbody>();
|
||||
rigidBody.useGravity = false;
|
||||
rigidBody.maxDepenetrationVelocity = 0;
|
||||
rigidBody.mass = 100;
|
||||
rigidBody.linearDamping = 100;
|
||||
rigidBody.interpolation = RigidbodyInterpolation.None;
|
||||
rigidBody.maxLinearVelocity = 0;
|
||||
rigidBody.detectCollisions = false;
|
||||
rigidBody.position = Vector3.zero;
|
||||
rigidBody.rotation = Quaternion.identity;
|
||||
rigidBody.transform.position = Vector3.zero;
|
||||
rigidBody.transform.rotation = Quaternion.identity;
|
||||
// NOTE: We don't use a sphere collider for this integration test because by the time we can
|
||||
// assure they don't collide and skew the results the NetworkObjects are already synchronized
|
||||
// with skewed results
|
||||
@@ -51,11 +63,22 @@ namespace Unity.Netcode.RuntimeTests
|
||||
m_ClientNetworkTransformPrefab.AddComponent<VerifyObjectIsSpawnedOnClient>();
|
||||
|
||||
m_NetworkTransformPrefab = CreateNetworkObjectPrefab("ServerAuthorityTest");
|
||||
var networkTransform = m_NetworkTransformPrefab.AddComponent<NetworkTransform>();
|
||||
var networkObject = m_ClientNetworkTransformPrefab.GetComponent<NetworkObject>();
|
||||
// When running in distributed authority mode, make the NetworkObject transferable
|
||||
networkObject.SetOwnershipStatus(m_DistributedAuthority ? NetworkObject.OwnershipStatus.Transferable : NetworkObject.OwnershipStatus.None);
|
||||
var networkTransform = m_NetworkTransformPrefab.AddComponent<TestClientNetworkTransform>();
|
||||
rigidBody = m_NetworkTransformPrefab.AddComponent<Rigidbody>();
|
||||
rigidBody.useGravity = false;
|
||||
rigidBody.maxDepenetrationVelocity = 0;
|
||||
rigidBody.linearDamping = 100;
|
||||
rigidBody.mass = 100;
|
||||
rigidBody.interpolation = RigidbodyInterpolation.None;
|
||||
rigidBody.maxLinearVelocity = 0;
|
||||
rigidBody.detectCollisions = false;
|
||||
rigidBody.position = Vector3.zero;
|
||||
rigidBody.rotation = Quaternion.identity;
|
||||
rigidBody.transform.position = Vector3.zero;
|
||||
rigidBody.transform.rotation = Quaternion.identity;
|
||||
// NOTE: We don't use a sphere collider for this integration test because by the time we can
|
||||
// assure they don't collide and skew the results the NetworkObjects are already synchronized
|
||||
// with skewed results
|
||||
@@ -276,10 +299,12 @@ namespace Unity.Netcode.RuntimeTests
|
||||
};
|
||||
if (m_MotionModel == MotionModels.UseRigidbody)
|
||||
{
|
||||
TestClientNetworkTransform.EnableLogState(m_EnableVerboseDebug);
|
||||
var ownerRigidbody = ownerInstance.GetComponent<Rigidbody>();
|
||||
ownerRigidbody.Move(valueSetByOwner, rotation);
|
||||
yield return new WaitForFixedUpdate();
|
||||
ownerRigidbody.linearVelocity = Vector3.zero;
|
||||
yield return s_DefaultWaitForTick;
|
||||
yield return new WaitForFixedUpdate();
|
||||
ownerInstance.transform.localScale = valueSetByOwner;
|
||||
}
|
||||
else
|
||||
@@ -312,15 +337,22 @@ namespace Unity.Netcode.RuntimeTests
|
||||
VerifyObjectIsSpawnedOnClient.ResetObjectTable();
|
||||
if (m_DistributedAuthority)
|
||||
{
|
||||
ownerInstance.NetworkObject.ChangeOwnership(networkManagerNonOwner.LocalClientId);
|
||||
Assert.True(nonOwnerInstance.OwnerClientId != networkManagerNonOwner.LocalClientId, $"Non-Owner Client-{networkManagerNonOwner.LocalClientId} was already the owner prior to changing ownership!");
|
||||
nonOwnerInstance.NetworkObject.ChangeOwnership(networkManagerNonOwner.LocalClientId);
|
||||
nonOwnerInstance.GetComponent<Rigidbody>().linearVelocity = Vector3.zero;
|
||||
Assert.True(nonOwnerInstance.OwnerClientId == networkManagerNonOwner.LocalClientId, $"Client-{networkManagerNonOwner.LocalClientId} failed to change ownership!");
|
||||
|
||||
LogNonOwnerRigidBody(3);
|
||||
yield return WaitForConditionOrTimeOut(() => ownerInstance.GetComponent<NetworkObject>().OwnerClientId == networkManagerNonOwner.LocalClientId);
|
||||
Assert.False(s_GlobalTimeoutHelper.TimedOut, $"Timed out waiting for original owner {networkManagerOwner.name}'s object instance {nonOwnerInstance.name} to change ownership!");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ServerNetworkManager.SpawnManager.ChangeOwnership(serverSideInstance.GetComponent<NetworkObject>(), networkManagerNonOwner.LocalClientId, true);
|
||||
LogNonOwnerRigidBody(3);
|
||||
yield return WaitForConditionOrTimeOut(() => nonOwnerInstance.GetComponent<NetworkObject>().OwnerClientId == networkManagerNonOwner.LocalClientId);
|
||||
Assert.False(s_GlobalTimeoutHelper.TimedOut, $"Timed out waiting for {networkManagerNonOwner.name}'s object instance {nonOwnerInstance.name} to change ownership!");
|
||||
}
|
||||
LogNonOwnerRigidBody(3);
|
||||
yield return WaitForConditionOrTimeOut(() => nonOwnerInstance.GetComponent<NetworkObject>().OwnerClientId == networkManagerNonOwner.LocalClientId);
|
||||
Assert.False(s_GlobalTimeoutHelper.TimedOut, $"Timed out waiting for {networkManagerNonOwner.name}'s object instance {nonOwnerInstance.name} to change ownership!");
|
||||
|
||||
LogNonOwnerRigidBody(4);
|
||||
// Re-assign the ownership references and wait for the non-owner instance to be notified of ownership change
|
||||
@@ -331,6 +363,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
yield return WaitForConditionOrTimeOut(() => VerifyObjectIsSpawnedOnClient.GetClientInstance(networkManagerNonOwner.LocalClientId) != null);
|
||||
nonOwnerInstance = VerifyObjectIsSpawnedOnClient.GetClientInstance(networkManagerNonOwner.LocalClientId);
|
||||
Assert.NotNull(nonOwnerInstance);
|
||||
Assert.True(!nonOwnerInstance.IsOwner, $"Ownership failed to change on Client-{networkManagerNonOwner.LocalClientId} side! Expected owner to be {networkManagerOwner.LocalClientId} but owner is still {networkManagerNonOwner.LocalClientId}!");
|
||||
|
||||
// Make sure the owner is not kinematic and the non-owner(s) are kinematic
|
||||
Assert.False(ownerInstance.GetComponent<Rigidbody>().isKinematic, $"{networkManagerOwner.name}'s object instance {ownerInstance.name} is kinematic when it should not be!");
|
||||
@@ -344,7 +377,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
Assert.False(s_GlobalTimeoutHelper.TimedOut, $"Timed out waiting for {networkManagerNonOwner.name}'s object instance {nonOwnerInstance.name} to change its transform!\n" +
|
||||
$"Expected Position: {valueSetByOwner} | Current Position: {transformToTest.position}\n" +
|
||||
$"Expected Rotation: {valueSetByOwner} | Current Rotation: {transformToTest.rotation.eulerAngles}\n" +
|
||||
$"Expected Scale: {valueSetByOwner} | Current Scale: {transformToTest.localScale}");
|
||||
$"Expected Scale: {valueSetByOwner} | Current Scale: {transformToTest.localScale}\n {nonOwnerInstance.GetComponent<TestClientNetworkTransform>().LogInfoBuilder}");
|
||||
|
||||
LogNonOwnerRigidBody(5);
|
||||
// Have the new owner change transform values and wait for those values to be applied on the non-owner side.
|
||||
@@ -358,6 +391,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
var ownerRigidbody = ownerInstance.GetComponent<Rigidbody>();
|
||||
ownerRigidbody.Move(valueSetByOwner, rotation);
|
||||
LogOwnerRigidBody(2);
|
||||
yield return new WaitForFixedUpdate();
|
||||
ownerInstance.GetComponent<NetworkTransform>().LogMotion = m_EnableVerboseDebug;
|
||||
nonOwnerInstance.GetComponent<NetworkTransform>().LogMotion = m_EnableVerboseDebug;
|
||||
ownerRigidbody.linearVelocity = Vector3.zero;
|
||||
@@ -377,10 +411,11 @@ namespace Unity.Netcode.RuntimeTests
|
||||
LogOwnerRigidBody(4);
|
||||
LogNonOwnerRigidBody(7);
|
||||
}
|
||||
|
||||
Assert.False(s_GlobalTimeoutHelper.TimedOut, $"Timed out waiting for {networkManagerNonOwner.name}'s object instance {nonOwnerInstance.name} to change its transform!\n" +
|
||||
$"Expected Position: {valueSetByOwner} | Current Position: {transformToTest.position}\n" +
|
||||
$"Expected Rotation: {valueSetByOwner} | Current Rotation: {transformToTest.rotation.eulerAngles}\n" +
|
||||
$"Expected Scale: {valueSetByOwner} | Current Scale: {transformToTest.localScale}");
|
||||
$"Expected Scale: {valueSetByOwner} | Current Scale: {transformToTest.localScale}\n {nonOwnerInstance.GetComponent<TestClientNetworkTransform>().LogInfoBuilder}");
|
||||
|
||||
// The last check is to verify non-owners cannot change transform values after ownership has changed
|
||||
nonOwnerInstance.transform.position = Vector3.zero;
|
||||
@@ -445,6 +480,12 @@ namespace Unity.Netcode.RuntimeTests
|
||||
Assert.True(nonOwnerInstance.transform.position == valueSetByOwner, $"{m_ClientNetworkManagers[0].name}'s object instance {nonOwnerInstance.name} was allowed to change its position! Expected: {Vector3.one} Is Currently:{nonOwnerInstance.transform.position}");
|
||||
}
|
||||
|
||||
protected override IEnumerator OnTearDown()
|
||||
{
|
||||
TestClientNetworkTransform.EnableLogState(false);
|
||||
return base.OnTearDown();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetworkTransformOwnershipTests helper behaviour
|
||||
/// </summary>
|
||||
@@ -457,6 +498,10 @@ namespace Unity.Netcode.RuntimeTests
|
||||
NetworkManagerRelativeSpawnedObjects.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For testing, just before changing ownership the table is cleared to assure that
|
||||
/// ownership tansfer occurs. This will add the new owner to the table.
|
||||
/// </summary>
|
||||
public override void OnGainedOwnership()
|
||||
{
|
||||
if (!NetworkManagerRelativeSpawnedObjects.ContainsKey(NetworkManager.LocalClientId))
|
||||
@@ -466,6 +511,10 @@ namespace Unity.Netcode.RuntimeTests
|
||||
base.OnGainedOwnership();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For testing, just before changing ownership the table is cleared to assure that
|
||||
/// ownership tansfer occurs. This will add the previous owner to the table.
|
||||
/// </summary>
|
||||
public override void OnLostOwnership()
|
||||
{
|
||||
if (!NetworkManagerRelativeSpawnedObjects.ContainsKey(NetworkManager.LocalClientId))
|
||||
@@ -515,28 +564,57 @@ namespace Unity.Netcode.RuntimeTests
|
||||
[DisallowMultipleComponent]
|
||||
internal class TestClientNetworkTransform : NetworkTransform
|
||||
{
|
||||
//public override void OnNetworkSpawn()
|
||||
//{
|
||||
// base.OnNetworkSpawn();
|
||||
// CanCommitToTransform = IsOwner;
|
||||
//}
|
||||
|
||||
//protected override void Update()
|
||||
//{
|
||||
// CanCommitToTransform = IsOwner;
|
||||
// base.Update();
|
||||
// if (NetworkManager.Singleton != null && (NetworkManager.Singleton.IsConnectedClient || NetworkManager.Singleton.IsListening))
|
||||
// {
|
||||
// if (CanCommitToTransform)
|
||||
// {
|
||||
// TryCommitTransformToServer(transform, NetworkManager.LocalTime.Time);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
protected override bool OnIsServerAuthoritative()
|
||||
public static void EnableLogState(bool enable)
|
||||
{
|
||||
return false;
|
||||
s_LogStateEnabled = enable;
|
||||
TrackByStateId = enable;
|
||||
}
|
||||
|
||||
private static bool s_LogStateEnabled;
|
||||
|
||||
internal StringBuilder LogInfoBuilder = new StringBuilder();
|
||||
|
||||
private void LogInfo(NetworkTransformState state)
|
||||
{
|
||||
if (s_LogStateEnabled)
|
||||
{
|
||||
LogInfoBuilder.AppendLine($"N:{name} | CID:{NetworkManager.LocalClientId} | SID: {state.StateId} | NT:{NetworkManager.ServerTime.Tick} | Pos: {transform.position} | Sc: {transform.localScale}");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnOwnershipChanged(ulong previous, ulong current)
|
||||
{
|
||||
|
||||
if (s_LogStateEnabled)
|
||||
{
|
||||
LogInfoBuilder.AppendLine($"Ownership Changed: {previous} --> {current} | Position: {transform.position}");
|
||||
}
|
||||
LogInfo(LocalAuthoritativeNetworkState);
|
||||
base.OnOwnershipChanged(previous, current);
|
||||
|
||||
// Assure no velocity is set on this object for this particular test
|
||||
if (current == NetworkManager.LocalClientId)
|
||||
{
|
||||
GetComponent<Rigidbody>().linearVelocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAuthorityPushTransformState(ref NetworkTransformState networkTransformState)
|
||||
{
|
||||
LogInfo(networkTransformState);
|
||||
base.OnAuthorityPushTransformState(ref networkTransformState);
|
||||
}
|
||||
|
||||
protected override void OnBeforeUpdateTransformState()
|
||||
{
|
||||
LogInfo(LocalAuthoritativeNetworkState);
|
||||
base.OnBeforeUpdateTransformState();
|
||||
}
|
||||
|
||||
protected override void OnNetworkTransformStateUpdated(ref NetworkTransformState oldState, ref NetworkTransformState newState)
|
||||
{
|
||||
LogInfo(newState);
|
||||
base.OnNetworkTransformStateUpdated(ref oldState, ref newState);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -791,7 +869,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
|
||||
foreach (var networkManager in m_NetworkManagers)
|
||||
{
|
||||
// Randomize the position
|
||||
// Randomize the position
|
||||
RandomizeObjectTransformPositions(m_SpawnObject);
|
||||
|
||||
// Create an instance owned by the specified networkmanager
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This test validates the SwitchTransformSpaceWhenParented setting under all network topologies
|
||||
/// This test validates the SwitchTransformSpaceWhenParented setting under all network topologies
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void SwitchTransformSpaceWhenParentedTest([Values(0.5f, 1.0f, 5.0f)] float scale)
|
||||
|
||||
Reference in New Issue
Block a user