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-pre.4] - 2024-08-21 ### Added - Added `NetworkVariable.CheckDirtyState` that is to be used in tandem with collections in order to detect whether the collection or an item within the collection has changed. (#3004) ### Fixed - Fixed issue where nested `NetworkTransform` components were not getting updated. (#3016) - Fixed issue by adding null checks in `NetworkVariableBase.CanClientRead` and `NetworkVariableBase.CanClientWrite` methods to ensure safe access to `NetworkBehaviour`. (#3012) - Fixed issue where `FixedStringSerializer<T>` was using `NetworkVariableSerialization<byte>.AreEqual` to determine if two bytes were equal causes an exception to be thrown due to no byte serializer having been defined. (#3009) - Fixed Issue where a state with dual triggers, inbound and outbound, could cause a false layer to layer state transition message to be sent to non-authority `NetworkAnimator` instances and cause a warning message to be logged. (#3008) - Fixed issue using collections within `NetworkVariable` where the collection would not detect changes to items or nested items. (#3004) - Fixed issue where `List`, `Dictionary`, and `HashSet` collections would not uniquely duplicate nested collections. (#3004) - Fixed issue where `NotAuthorityTarget` would include the service observer in the list of targets to send the RPC to as opposed to excluding the service observer as it should. (#3000) - Fixed issue where `ProxyRpcTargetGroup` could attempt to send a message if there were no targets to send to. (#3000) ### Changed - Changed `NetworkAnimator` to automatically switch to owner authoritative mode when using a distributed authority network topology. (#3021) - Changed permissions exception thrown in `NetworkList` to exiting early with a logged error that is now a unified permissions message within `NetworkVariableBase`. (#3004) - Changed permissions exception thrown in `NetworkVariable.Value` to exiting early with a logged error that is now a unified permissions message within `NetworkVariableBase`. (#3004)
115 lines
3.8 KiB
C#
115 lines
3.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using NUnit.Framework;
|
|
using Unity.Netcode.TestHelpers.Runtime;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
|
|
namespace Unity.Netcode.RuntimeTests
|
|
{
|
|
// This is a bit of a quirky test.
|
|
// Addresses MTT-4386 #2109
|
|
// Where the NetworkVariable updates would be repeated on some clients.
|
|
// The twist comes fom the updates needing to happens very specifically for the issue to repro in tests
|
|
|
|
internal class OwnerModifiedObject : NetworkBehaviour, INetworkUpdateSystem
|
|
{
|
|
public NetworkList<int> MyNetworkList;
|
|
|
|
internal static int Updates = 0;
|
|
|
|
public static bool EnableVerbose;
|
|
|
|
private void Awake()
|
|
{
|
|
MyNetworkList = new NetworkList<int>(new List<int>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
|
|
MyNetworkList.OnListChanged += Changed;
|
|
}
|
|
|
|
public void Changed(NetworkListEvent<int> listEvent)
|
|
{
|
|
var expected = 0;
|
|
var listString = "";
|
|
foreach (var i in MyNetworkList)
|
|
{
|
|
Assert.AreEqual(i, expected);
|
|
expected++;
|
|
listString += i.ToString();
|
|
}
|
|
if (EnableVerbose)
|
|
{
|
|
Debug.Log($"[{NetworkManager.LocalClientId}] Value changed to {listString}");
|
|
}
|
|
|
|
Updates++;
|
|
}
|
|
|
|
public bool AddValues;
|
|
|
|
public NetworkUpdateStage NetworkUpdateStageToCheck;
|
|
|
|
private int m_ValueToUpdate;
|
|
|
|
public void NetworkUpdate(NetworkUpdateStage updateStage)
|
|
{
|
|
if (updateStage == NetworkUpdateStageToCheck)
|
|
{
|
|
if (AddValues)
|
|
{
|
|
MyNetworkList.Add(m_ValueToUpdate++);
|
|
AddValues = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void OnDestroy()
|
|
{
|
|
NetworkUpdateLoop.UnregisterAllNetworkUpdates(this);
|
|
base.OnDestroy();
|
|
}
|
|
|
|
public void InitializeLastCient()
|
|
{
|
|
NetworkUpdateLoop.RegisterAllNetworkUpdates(this);
|
|
}
|
|
}
|
|
|
|
[TestFixture(HostOrServer.DAHost)]
|
|
[TestFixture(HostOrServer.Host)]
|
|
internal class OwnerModifiedTests : NetcodeIntegrationTest
|
|
{
|
|
protected override int NumberOfClients => 2;
|
|
|
|
public OwnerModifiedTests(HostOrServer hostOrServer) : base(hostOrServer) { }
|
|
|
|
protected override void OnCreatePlayerPrefab()
|
|
{
|
|
m_PlayerPrefab.AddComponent<OwnerModifiedObject>();
|
|
}
|
|
|
|
[UnityTest]
|
|
public IEnumerator OwnerModifiedTest()
|
|
{
|
|
OwnerModifiedObject.EnableVerbose = m_EnableVerboseDebug;
|
|
// We use this to assure we are the "last client" connected.
|
|
yield return CreateAndStartNewClient();
|
|
var ownerModLastClient = m_ClientNetworkManagers[2].LocalClient.PlayerObject.GetComponent<OwnerModifiedObject>();
|
|
ownerModLastClient.InitializeLastCient();
|
|
|
|
// Run through all update loops setting the value once every 5 frames
|
|
foreach (var updateLoopType in System.Enum.GetValues(typeof(NetworkUpdateStage)))
|
|
{
|
|
ownerModLastClient.NetworkUpdateStageToCheck = (NetworkUpdateStage)updateLoopType;
|
|
VerboseDebug($"Testing Update Stage: {ownerModLastClient.NetworkUpdateStageToCheck}");
|
|
ownerModLastClient.AddValues = true;
|
|
yield return WaitForTicks(m_ServerNetworkManager, 5);
|
|
}
|
|
|
|
yield return WaitForTicks(m_ServerNetworkManager, 5);
|
|
|
|
// We'll have at least one update per stage per client, if all goes well.
|
|
Assert.True(OwnerModifiedObject.Updates > 20);
|
|
}
|
|
}
|
|
}
|