com.unity.netcode.gameobjects@2.0.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.0.0] - 2024-09-12 ### Added - Added tooltips for all of the `NetworkObject` component's properties. (#3052) - Added message size validation to named and unnamed message sending functions for better error messages. (#3049) - Added "Check for NetworkObject Component" property to the Multiplayer->Netcode for GameObjects project settings. When disabled, this will bypass the in-editor `NetworkObject` check on `NetworkBehaviour` components. (#3031) - Added `NetworkTransform.SwitchTransformSpaceWhenParented` property that, when enabled, will handle the world to local, local to world, and local to local transform space transitions when interpolation is enabled. (#3013) - Added `NetworkTransform.TickSyncChildren` that, when enabled, will tick synchronize nested and/or child `NetworkTransform` components to eliminate any potential visual jittering that could occur if the `NetworkTransform` instances get into a state where their state updates are landing on different network ticks. (#3013) - Added `NetworkObject.AllowOwnerToParent` property to provide the ability to allow clients to parent owned objects when running in a client-server network topology. (#3013) - Added `NetworkObject.SyncOwnerTransformWhenParented` property to provide a way to disable applying the server's transform information in the parenting message on the client owner instance which can be useful for owner authoritative motion models. (#3013) - Added `NetcodeEditorBase` editor helper class to provide easier modification and extension of the SDK's components. (#3013) ### Fixed - Fixed issue where `NetworkAnimator` would send updates to non-observer clients. (#3057) - Fixed issue where an exception could occur when receiving a universal RPC for a `NetworkObject` that has been despawned. (#3052) - Fixed issue where a NetworkObject hidden from a client that is then promoted to be session owner was not being synchronized with newly joining clients.(#3051) - Fixed issue where clients could have a wrong time delta on `NetworkVariableBase` which could prevent from sending delta state updates. (#3045) - Fixed issue where setting a prefab hash value during connection approval but not having a player prefab assigned could cause an exception when spawning a player. (#3042) - Fixed issue where the `NetworkSpawnManager.HandleNetworkObjectShow` could throw an exception if one of the `NetworkObject` components to show was destroyed during the same frame. (#3030) - Fixed issue where the `NetworkManagerHelper` was continuing to check for hierarchy changes when in play mode. (#3026) - Fixed issue with newly/late joined clients and `NetworkTransform` synchronization of parented `NetworkObject` instances. (#3013) - Fixed issue with smooth transitions between transform spaces when interpolation is enabled (requires `NetworkTransform.SwitchTransformSpaceWhenParented` to be enabled). (#3013) ### Changed - Changed `NetworkTransformEditor` now uses `NetworkTransform` as the base type class to assure it doesn't display a foldout group when using the base `NetworkTransform` component class. (#3052) - Changed `NetworkAnimator.Awake` is now a protected virtual method. (#3052) - Changed when invoking `NetworkManager.ConnectionManager.DisconnectClient` during a distributed authority session a more appropriate message is logged. (#3052) - Changed `NetworkTransformEditor` so it now derives from `NetcodeEditorBase`. (#3013) - Changed `NetworkRigidbodyBaseEditor` so it now derives from `NetcodeEditorBase`. (#3013) - Changed `NetworkManagerEditor` so it now derives from `NetcodeEditorBase`. (#3013)
This commit is contained in:
@@ -200,9 +200,8 @@ namespace Unity.Netcode.RuntimeTests
|
||||
/// </summary>
|
||||
/// <param name="testWithHost">Determines if we are running as a server or host</param>
|
||||
/// <param name="authority">Determines if we are using server or owner authority</param>
|
||||
public NetworkTransformBase(HostOrServer testWithHost, Authority authority, RotationCompression rotationCompression, Rotation rotation, Precision precision)
|
||||
public NetworkTransformBase(HostOrServer testWithHost, Authority authority, RotationCompression rotationCompression, Rotation rotation, Precision precision) : base(testWithHost)
|
||||
{
|
||||
m_UseHost = testWithHost == HostOrServer.Host;
|
||||
m_Authority = authority;
|
||||
m_Precision = precision;
|
||||
m_RotationCompression = rotationCompression;
|
||||
@@ -376,6 +375,18 @@ namespace Unity.Netcode.RuntimeTests
|
||||
return true;
|
||||
}
|
||||
|
||||
protected bool AllFirstLevelChildObjectInstancesHaveChild()
|
||||
{
|
||||
foreach (var instance in ChildObjectComponent.ClientInstances.Values)
|
||||
{
|
||||
if (instance.transform.parent == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected bool AllChildObjectInstancesHaveChild()
|
||||
{
|
||||
foreach (var instance in ChildObjectComponent.ClientInstances.Values)
|
||||
@@ -398,6 +409,33 @@ namespace Unity.Netcode.RuntimeTests
|
||||
return true;
|
||||
}
|
||||
|
||||
protected bool AllFirstLevelChildObjectInstancesHaveNoParent()
|
||||
{
|
||||
foreach (var instance in ChildObjectComponent.ClientInstances.Values)
|
||||
{
|
||||
if (instance.transform.parent != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected bool AllSubChildObjectInstancesHaveNoParent()
|
||||
{
|
||||
if (ChildObjectComponent.HasSubChild)
|
||||
{
|
||||
foreach (var instance in ChildObjectComponent.ClientSubChildInstances.Values)
|
||||
{
|
||||
if (instance.transform.parent != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A wait condition specific method that assures the local space coordinates
|
||||
/// are not impacted by NetworkTransform when parented.
|
||||
|
||||
@@ -101,6 +101,225 @@ namespace Unity.Netcode.RuntimeTests
|
||||
}
|
||||
|
||||
#if !MULTIPLAYER_TOOLS
|
||||
|
||||
private void UpdateTransformLocal(Components.NetworkTransform networkTransformTestComponent)
|
||||
{
|
||||
networkTransformTestComponent.transform.localPosition += GetRandomVector3(0.5f, 2.0f);
|
||||
var rotation = networkTransformTestComponent.transform.localRotation;
|
||||
var eulerRotation = rotation.eulerAngles;
|
||||
eulerRotation += GetRandomVector3(0.5f, 5.0f);
|
||||
rotation.eulerAngles = eulerRotation;
|
||||
networkTransformTestComponent.transform.localRotation = rotation;
|
||||
}
|
||||
|
||||
private void UpdateTransformWorld(Components.NetworkTransform networkTransformTestComponent)
|
||||
{
|
||||
networkTransformTestComponent.transform.position += GetRandomVector3(0.5f, 2.0f);
|
||||
var rotation = networkTransformTestComponent.transform.rotation;
|
||||
var eulerRotation = rotation.eulerAngles;
|
||||
eulerRotation += GetRandomVector3(0.5f, 5.0f);
|
||||
rotation.eulerAngles = eulerRotation;
|
||||
networkTransformTestComponent.transform.rotation = rotation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This test validates the SwitchTransformSpaceWhenParented setting under all network topologies
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void SwitchTransformSpaceWhenParentedTest([Values(0.5f, 1.0f, 5.0f)] float scale)
|
||||
{
|
||||
m_UseParentingThreshold = true;
|
||||
// Get the NetworkManager that will have authority in order to spawn with the correct authority
|
||||
var isServerAuthority = m_Authority == Authority.ServerAuthority;
|
||||
var authorityNetworkManager = m_ServerNetworkManager;
|
||||
if (!isServerAuthority)
|
||||
{
|
||||
authorityNetworkManager = m_ClientNetworkManagers[0];
|
||||
}
|
||||
|
||||
var childAuthorityNetworkManager = m_ClientNetworkManagers[0];
|
||||
if (!isServerAuthority)
|
||||
{
|
||||
childAuthorityNetworkManager = m_ServerNetworkManager;
|
||||
}
|
||||
|
||||
// Spawn a parent and children
|
||||
ChildObjectComponent.HasSubChild = true;
|
||||
// Modify our prefabs for this specific test
|
||||
m_ParentObject.GetComponent<NetworkTransformTestComponent>().TickSyncChildren = true;
|
||||
m_ChildObject.GetComponent<ChildObjectComponent>().SwitchTransformSpaceWhenParented = true;
|
||||
m_ChildObject.GetComponent<ChildObjectComponent>().TickSyncChildren = true;
|
||||
m_SubChildObject.GetComponent<ChildObjectComponent>().SwitchTransformSpaceWhenParented = true;
|
||||
m_SubChildObject.GetComponent<ChildObjectComponent>().TickSyncChildren = true;
|
||||
m_ChildObject.AllowOwnerToParent = true;
|
||||
m_SubChildObject.AllowOwnerToParent = true;
|
||||
|
||||
|
||||
var authoritySideParent = SpawnObject(m_ParentObject.gameObject, authorityNetworkManager).GetComponent<NetworkObject>();
|
||||
var authoritySideChild = SpawnObject(m_ChildObject.gameObject, childAuthorityNetworkManager).GetComponent<NetworkObject>();
|
||||
var authoritySideSubChild = SpawnObject(m_SubChildObject.gameObject, childAuthorityNetworkManager).GetComponent<NetworkObject>();
|
||||
|
||||
// Assure all of the child object instances are spawned before proceeding to parenting
|
||||
var success = WaitForConditionOrTimeOutWithTimeTravel(AllChildObjectInstancesAreSpawned);
|
||||
Assert.True(success, "Timed out waiting for all child instances to be spawned!");
|
||||
|
||||
// Get the owner instance if in client-server mode with owner authority
|
||||
if (m_Authority == Authority.OwnerAuthority && !m_DistributedAuthority)
|
||||
{
|
||||
authoritySideParent = s_GlobalNetworkObjects[authoritySideParent.OwnerClientId][authoritySideParent.NetworkObjectId];
|
||||
authoritySideChild = s_GlobalNetworkObjects[authoritySideChild.OwnerClientId][authoritySideChild.NetworkObjectId];
|
||||
authoritySideSubChild = s_GlobalNetworkObjects[authoritySideSubChild.OwnerClientId][authoritySideSubChild.NetworkObjectId];
|
||||
}
|
||||
|
||||
// Get the authority parent and child instances
|
||||
m_AuthorityParentObject = NetworkTransformTestComponent.AuthorityInstance.NetworkObject;
|
||||
m_AuthorityChildObject = ChildObjectComponent.AuthorityInstance.NetworkObject;
|
||||
m_AuthoritySubChildObject = ChildObjectComponent.AuthoritySubInstance.NetworkObject;
|
||||
|
||||
// The child NetworkTransform will use world space when world position stays and
|
||||
// local space when world position does not stay when parenting.
|
||||
ChildObjectComponent.AuthorityInstance.UseHalfFloatPrecision = m_Precision == Precision.Half;
|
||||
ChildObjectComponent.AuthorityInstance.UseQuaternionSynchronization = m_Rotation == Rotation.Quaternion;
|
||||
ChildObjectComponent.AuthorityInstance.UseQuaternionCompression = m_RotationCompression == RotationCompression.QuaternionCompress;
|
||||
|
||||
ChildObjectComponent.AuthoritySubInstance.UseHalfFloatPrecision = m_Precision == Precision.Half;
|
||||
ChildObjectComponent.AuthoritySubInstance.UseQuaternionSynchronization = m_Rotation == Rotation.Quaternion;
|
||||
ChildObjectComponent.AuthoritySubInstance.UseQuaternionCompression = m_RotationCompression == RotationCompression.QuaternionCompress;
|
||||
|
||||
// Set whether we are interpolating or not
|
||||
m_AuthorityParentNetworkTransform = m_AuthorityParentObject.GetComponent<NetworkTransformTestComponent>();
|
||||
m_AuthorityParentNetworkTransform.Interpolate = true;
|
||||
m_AuthorityChildNetworkTransform = m_AuthorityChildObject.GetComponent<ChildObjectComponent>();
|
||||
m_AuthorityChildNetworkTransform.Interpolate = true;
|
||||
m_AuthoritySubChildNetworkTransform = m_AuthoritySubChildObject.GetComponent<ChildObjectComponent>();
|
||||
m_AuthoritySubChildNetworkTransform.Interpolate = true;
|
||||
|
||||
// Apply a scale to the parent object to make sure the scale on the child is properly updated on
|
||||
// non-authority instances.
|
||||
var halfScale = scale * 0.5f;
|
||||
m_AuthorityParentObject.transform.localScale = GetRandomVector3(scale - halfScale, scale + halfScale);
|
||||
m_AuthorityChildObject.transform.localScale = GetRandomVector3(scale - halfScale, scale + halfScale);
|
||||
m_AuthoritySubChildObject.transform.localScale = GetRandomVector3(scale - halfScale, scale + halfScale);
|
||||
|
||||
// Allow one tick for authority to update these changes
|
||||
TimeTravelAdvanceTick();
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(PositionRotationScaleMatches);
|
||||
|
||||
Assert.True(success, "All transform values did not match prior to parenting!");
|
||||
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(PositionRotationScaleMatches);
|
||||
|
||||
Assert.True(success, "All transform values did not match prior to parenting!");
|
||||
|
||||
// Move things around while parenting and removing the parent
|
||||
// Not the absolute "perfect" test, but it validates the clients all synchronize
|
||||
// parenting and transform values.
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
// Provide two network ticks for interpolation to finalize
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelAdvanceTick();
|
||||
|
||||
// This validates each child instance has preserved their local space values
|
||||
AllChildrenLocalTransformValuesMatch(false, ChildrenTransformCheckType.Connected_Clients);
|
||||
|
||||
// This validates each sub-child instance has preserved their local space values
|
||||
AllChildrenLocalTransformValuesMatch(true, ChildrenTransformCheckType.Connected_Clients);
|
||||
// Parent while in motion
|
||||
if (i == 5)
|
||||
{
|
||||
// Parent the child under the parent with the current world position stays setting
|
||||
Assert.True(authoritySideChild.TrySetParent(authoritySideParent.transform), $"[Child][Client-{authoritySideChild.NetworkManagerOwner.LocalClientId}] Failed to set child's parent!");
|
||||
|
||||
// This waits for all child instances to be parented
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(AllFirstLevelChildObjectInstancesHaveChild, 300);
|
||||
Assert.True(success, "Timed out waiting for all instances to have parented a child!");
|
||||
}
|
||||
|
||||
if (i == 10)
|
||||
{
|
||||
// Parent the sub-child under the child with the current world position stays setting
|
||||
Assert.True(authoritySideSubChild.TrySetParent(authoritySideChild.transform), $"[Sub-Child][Client-{authoritySideSubChild.NetworkManagerOwner.LocalClientId}] Failed to set sub-child's parent!");
|
||||
|
||||
// This waits for all child instances to be parented
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(AllChildObjectInstancesHaveChild, 300);
|
||||
Assert.True(success, "Timed out waiting for all instances to have parented a child!");
|
||||
}
|
||||
|
||||
if (i == 15)
|
||||
{
|
||||
// Verify that a late joining client will synchronize to the parented NetworkObjects properly
|
||||
CreateAndStartNewClientWithTimeTravel();
|
||||
|
||||
// Assure all of the child object instances are spawned (basically for the newly connected client)
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(AllChildObjectInstancesAreSpawned, 300);
|
||||
Assert.True(success, "Timed out waiting for all child instances to be spawned!");
|
||||
|
||||
// This waits for all child instances to be parented
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(AllChildObjectInstancesHaveChild, 300);
|
||||
Assert.True(success, "Timed out waiting for all instances to have parented a child!");
|
||||
|
||||
// This validates each child instance has preserved their local space values
|
||||
AllChildrenLocalTransformValuesMatch(false, ChildrenTransformCheckType.Late_Join_Client);
|
||||
|
||||
// This validates each sub-child instance has preserved their local space values
|
||||
AllChildrenLocalTransformValuesMatch(true, ChildrenTransformCheckType.Late_Join_Client);
|
||||
}
|
||||
|
||||
if (i == 20)
|
||||
{
|
||||
// Remove the parent
|
||||
Assert.True(authoritySideSubChild.TryRemoveParent(), $"[Sub-Child][Client-{authoritySideSubChild.NetworkManagerOwner.LocalClientId}] Failed to set sub-child's parent!");
|
||||
|
||||
// This waits for all child instances to have the parent removed
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(AllSubChildObjectInstancesHaveNoParent, 300);
|
||||
Assert.True(success, "Timed out waiting for all instances remove the parent!");
|
||||
}
|
||||
|
||||
if (i == 25)
|
||||
{
|
||||
// Parent the child under the parent with the current world position stays setting
|
||||
Assert.True(authoritySideChild.TryRemoveParent(), $"[Child][Client-{authoritySideChild.NetworkManagerOwner.LocalClientId}] Failed to remove parent!");
|
||||
|
||||
// This waits for all child instances to be parented
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(AllFirstLevelChildObjectInstancesHaveNoParent, 300);
|
||||
Assert.True(success, "Timed out waiting for all instances remove the parent!");
|
||||
}
|
||||
UpdateTransformWorld(m_AuthorityParentNetworkTransform);
|
||||
if (m_AuthorityChildNetworkTransform.InLocalSpace)
|
||||
{
|
||||
UpdateTransformLocal(m_AuthorityChildNetworkTransform);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateTransformWorld(m_AuthorityChildNetworkTransform);
|
||||
}
|
||||
|
||||
if (m_AuthoritySubChildNetworkTransform.InLocalSpace)
|
||||
{
|
||||
UpdateTransformLocal(m_AuthoritySubChildNetworkTransform);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateTransformWorld(m_AuthoritySubChildNetworkTransform);
|
||||
}
|
||||
}
|
||||
|
||||
success = WaitForConditionOrTimeOutWithTimeTravel(PositionRotationScaleMatches, 300);
|
||||
|
||||
Assert.True(success, "All transform values did not match prior to parenting!");
|
||||
|
||||
// Revert the modifications made for this specific test
|
||||
m_ParentObject.GetComponent<NetworkTransformTestComponent>().TickSyncChildren = false;
|
||||
m_ChildObject.GetComponent<ChildObjectComponent>().SwitchTransformSpaceWhenParented = false;
|
||||
m_ChildObject.GetComponent<ChildObjectComponent>().TickSyncChildren = false;
|
||||
m_ChildObject.AllowOwnerToParent = false;
|
||||
m_SubChildObject.AllowOwnerToParent = false;
|
||||
m_SubChildObject.GetComponent<ChildObjectComponent>().SwitchTransformSpaceWhenParented = false;
|
||||
m_SubChildObject.GetComponent<ChildObjectComponent>().TickSyncChildren = false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Validates that transform values remain the same when a NetworkTransform is
|
||||
/// parented under another NetworkTransform under all of the possible axial conditions
|
||||
@@ -410,6 +629,7 @@ namespace Unity.Netcode.RuntimeTests
|
||||
Assert.AreEqual(Vector3.zero, m_NonAuthoritativeTransform.transform.position, "server side pos should be zero at first"); // sanity check
|
||||
|
||||
TimeTravelAdvanceTick();
|
||||
TimeTravelToNextTick();
|
||||
|
||||
m_AuthoritativeTransform.StatePushed = false;
|
||||
var nextPosition = GetRandomVector3(2f, 30f);
|
||||
|
||||
Reference in New Issue
Block a user