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.0.1] - 2022-08-23 ### Changed - Changed version to 1.0.1. (#2131) - Updated dependency on `com.unity.transport` to 1.2.0. (#2129) - When using `UnityTransport`, _reliable_ payloads are now allowed to exceed the configured 'Max Payload Size'. Unreliable payloads remain bounded by this setting. (#2081) - Preformance improvements for cases with large number of NetworkObjects, by not iterating over all unchanged NetworkObjects ### Fixed - Fixed an issue where reading/writing more than 8 bits at a time with BitReader/BitWriter would write/read from the wrong place, returning and incorrect result. (#2130) - Fixed issue with the internal `NetworkTransformState.m_Bitset` flag not getting cleared upon the next tick advancement. (#2110) - Fixed interpolation issue with `NetworkTransform.Teleport`. (#2110) - Fixed issue where the authoritative side was interpolating its transform. (#2110) - Fixed Owner-written NetworkVariable infinitely write themselves (#2109) - Fixed NetworkList issue that showed when inserting at the very end of a NetworkList (#2099) - Fixed issue where a client owner of a `NetworkVariable` with both owner read and write permissions would not update the server side when changed. (#2097) - Fixed issue when attempting to spawn a parent `GameObject`, with `NetworkObject` component attached, that has one or more child `GameObject`s, that are inactive in the hierarchy, with `NetworkBehaviour` components it will no longer attempt to spawn the associated `NetworkBehaviour`(s) or invoke ownership changed notifications but will log a warning message. (#2096) - Fixed an issue where destroying a NetworkBehaviour would not deregister it from the parent NetworkObject, leading to exceptions when the parent was later destroyed. (#2091) - Fixed issue where `NetworkObject.NetworkHide` was despawning and destroying, as opposed to only despawning, in-scene placed `NetworkObject`s. (#2086) - Fixed `NetworkAnimator` synchronizing transitions twice due to it detecting the change in animation state once a transition is started by a trigger. (#2084) - Fixed issue where `NetworkAnimator` would not synchronize a looping animation for late joining clients if it was at the very end of its loop. (#2076) - Fixed issue where `NetworkAnimator` was not removing its subscription from `OnClientConnectedCallback` when despawned during the shutdown sequence. (#2074) - Fixed IsServer and IsClient being set to false before object despawn during the shutdown sequence. (#2074) - Fixed NetworkList Value event on the server. PreviousValue is now set correctly when a new value is set through property setter. (#2067) - Fixed NetworkLists not populating on client. NetworkList now uses the most recent list as opposed to the list at the end of previous frame, when sending full updates to dynamically spawned NetworkObject. The difference in behaviour is required as scene management spawns those objects at a different time in the frame, relative to updates. (#2062)
138 lines
5.7 KiB
C#
138 lines
5.7 KiB
C#
using System.Collections;
|
|
using Unity.Netcode.Components;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
using Unity.Netcode.TestHelpers.Runtime;
|
|
|
|
|
|
namespace Unity.Netcode.RuntimeTests
|
|
{
|
|
public class TransformInterpolationObject : NetworkBehaviour
|
|
{
|
|
// Set the minimum threshold which we will use as our margin of error
|
|
public const float MinThreshold = 0.001f;
|
|
|
|
public bool CheckPosition;
|
|
public bool IsMoving;
|
|
public bool IsFixed;
|
|
|
|
private void Update()
|
|
{
|
|
// Check the position of the nested object on the client
|
|
if (CheckPosition)
|
|
{
|
|
if (transform.position.y < -MinThreshold || transform.position.y > 100.0f + MinThreshold)
|
|
{
|
|
Debug.LogError($"Interpolation failure. transform.position.y is {transform.position.y}. Should be between 0.0 and 100.0");
|
|
}
|
|
}
|
|
|
|
// Move the nested object on the server
|
|
if (IsMoving)
|
|
{
|
|
var y = Time.realtimeSinceStartup % 10.0f;
|
|
|
|
// change the space between local and global every second
|
|
GetComponent<NetworkTransform>().InLocalSpace = ((int)y % 2 == 0);
|
|
|
|
transform.position = new Vector3(0.0f, y * 10, 0.0f);
|
|
}
|
|
|
|
// On the server, make sure to keep the parent object at a fixed position
|
|
if (IsFixed)
|
|
{
|
|
transform.position = new Vector3(1000.0f, 1000.0f, 1000.0f);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class TransformInterpolationTests : NetcodeIntegrationTest
|
|
{
|
|
protected override int NumberOfClients => 1;
|
|
|
|
private GameObject m_PrefabToSpawn;
|
|
|
|
private NetworkObject m_SpawnedAsNetworkObject;
|
|
private NetworkObject m_SpawnedObjectOnClient;
|
|
|
|
private NetworkObject m_BaseAsNetworkObject;
|
|
private NetworkObject m_BaseOnClient;
|
|
|
|
|
|
protected override void OnServerAndClientsCreated()
|
|
{
|
|
m_PrefabToSpawn = CreateNetworkObjectPrefab("InterpTestObject");
|
|
var networkTransform = m_PrefabToSpawn.AddComponent<NetworkTransform>();
|
|
networkTransform.PositionThreshold = TransformInterpolationObject.MinThreshold;
|
|
m_PrefabToSpawn.AddComponent<TransformInterpolationObject>();
|
|
}
|
|
|
|
private IEnumerator RefreshNetworkObjects()
|
|
{
|
|
var clientId = m_ClientNetworkManagers[0].LocalClientId;
|
|
yield return WaitForConditionOrTimeOut(() => s_GlobalNetworkObjects.ContainsKey(clientId) &&
|
|
s_GlobalNetworkObjects[clientId].ContainsKey(m_BaseAsNetworkObject.NetworkObjectId) &&
|
|
s_GlobalNetworkObjects[clientId].ContainsKey(m_SpawnedAsNetworkObject.NetworkObjectId));
|
|
|
|
Assert.False(s_GlobalTimeoutHelper.TimedOut, $"Timed out waiting for client side {nameof(NetworkObject)} ID of {m_SpawnedAsNetworkObject.NetworkObjectId}");
|
|
|
|
m_BaseOnClient = s_GlobalNetworkObjects[clientId][m_BaseAsNetworkObject.NetworkObjectId];
|
|
// make sure the objects are set with the right network manager
|
|
m_BaseOnClient.NetworkManagerOwner = m_ClientNetworkManagers[0];
|
|
|
|
m_SpawnedObjectOnClient = s_GlobalNetworkObjects[clientId][m_SpawnedAsNetworkObject.NetworkObjectId];
|
|
// make sure the objects are set with the right network manager
|
|
m_SpawnedObjectOnClient.NetworkManagerOwner = m_ClientNetworkManagers[0];
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator TransformInterpolationTest()
|
|
{
|
|
// create an object
|
|
var spawnedObject = Object.Instantiate(m_PrefabToSpawn);
|
|
var baseObject = Object.Instantiate(m_PrefabToSpawn);
|
|
baseObject.GetComponent<NetworkObject>().NetworkManagerOwner = m_ServerNetworkManager;
|
|
baseObject.GetComponent<NetworkObject>().Spawn();
|
|
|
|
m_SpawnedAsNetworkObject = spawnedObject.GetComponent<NetworkObject>();
|
|
m_SpawnedAsNetworkObject.NetworkManagerOwner = m_ServerNetworkManager;
|
|
|
|
m_BaseAsNetworkObject = baseObject.GetComponent<NetworkObject>();
|
|
m_BaseAsNetworkObject.NetworkManagerOwner = m_ServerNetworkManager;
|
|
|
|
|
|
m_SpawnedAsNetworkObject.TrySetParent(baseObject);
|
|
|
|
m_SpawnedAsNetworkObject.Spawn();
|
|
|
|
yield return RefreshNetworkObjects();
|
|
|
|
m_SpawnedAsNetworkObject.TrySetParent(baseObject);
|
|
|
|
baseObject.GetComponent<TransformInterpolationObject>().IsFixed = true;
|
|
spawnedObject.GetComponent<TransformInterpolationObject>().IsMoving = true;
|
|
spawnedObject.GetComponent<NetworkTransform>().SetMaxInterpolationBound(1.0f);
|
|
|
|
const float maxPlacementError = 0.01f;
|
|
|
|
// Wait for the base object to place itself on both instances
|
|
while (m_BaseOnClient.transform.position.y < 1000 - maxPlacementError ||
|
|
m_BaseOnClient.transform.position.y > 1000 + maxPlacementError ||
|
|
baseObject.transform.position.y < 1000 - maxPlacementError ||
|
|
baseObject.transform.position.y > 1000 + maxPlacementError)
|
|
{
|
|
yield return new WaitForSeconds(0.01f);
|
|
}
|
|
|
|
m_SpawnedObjectOnClient.GetComponent<NetworkTransform>().SetMaxInterpolationBound(1.0f);
|
|
m_SpawnedObjectOnClient.GetComponent<TransformInterpolationObject>().CheckPosition = true;
|
|
|
|
// Test that interpolation works correctly for 10 seconds
|
|
// Increasing this duration gives you the opportunity to go check in the Editor how the objects are setup
|
|
// and how they move
|
|
yield return new WaitForSeconds(10.0f);
|
|
}
|
|
}
|
|
}
|