This repository has been archived on 2025-04-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
com.unity.netcode.gameobjects/Tests/Runtime/NetworkBehaviourGenericTests.cs
Unity Technologies e15bd056c5 com.unity.netcode.gameobjects@1.0.1
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)
2022-08-23 00:00:00 +00:00

152 lines
6.0 KiB
C#

using System.Collections;
using UnityEngine;
using UnityEngine.TestTools;
using Unity.Netcode.TestHelpers.Runtime;
using Unity.Netcode.Components;
namespace Unity.Netcode.RuntimeTests
{
/// <summary>
/// This class is for testing general fixes or functionality of NetworkBehaviours
/// </summary>
public class NetworkBehaviourGenericTests : NetcodeIntegrationTest
{
protected override int NumberOfClients => 0;
private bool m_AllowServerToStart;
protected override bool CanStartServerAndClients()
{
return m_AllowServerToStart;
}
public class SimpleNetworkBehaviour : NetworkBehaviour
{
public bool OnNetworkDespawnCalled;
public override void OnNetworkDespawn()
{
OnNetworkDespawnCalled = true;
base.OnNetworkDespawn();
}
}
protected override IEnumerator OnSetup()
{
m_AllowServerToStart = false;
return base.OnSetup();
}
/// <summary>
/// This validates the fix for when a child GameObject with a NetworkBehaviour
/// is deleted while the parent GameObject with a NetworkObject is spawned and
/// is not deleted until a later time would cause an exception due to the
/// NetworkBehaviour not being removed from the NetworkObject.ChildNetworkBehaviours
/// list.
/// </summary>
[UnityTest]
public IEnumerator ValidatedDisableddNetworkBehaviourWarning()
{
m_AllowServerToStart = true;
yield return s_DefaultWaitForTick;
// Now just start the Host
yield return StartServerAndClients();
var parentObject = new GameObject();
var childObject = new GameObject();
childObject.name = "ChildObject";
childObject.transform.parent = parentObject.transform;
var parentNetworkObject = parentObject.AddComponent<NetworkObject>();
var childBehaviour = childObject.AddComponent<NetworkTransform>();
// Set the child object to be inactive in the hierarchy
childObject.SetActive(false);
LogAssert.Expect(LogType.Warning, $"{childObject.name} is disabled! Netcode for GameObjects does not support disabled NetworkBehaviours! The {childBehaviour.GetType().Name} component was skipped during ownership assignment!");
LogAssert.Expect(LogType.Warning, $"{childObject.name} is disabled! Netcode for GameObjects does not support spawning disabled NetworkBehaviours! The {childBehaviour.GetType().Name} component was skipped during spawn!");
parentNetworkObject.Spawn();
yield return s_DefaultWaitForTick;
}
/// <summary>
/// This test validates a fix to NetworkBehaviour.NetworkObject when
/// the NetworkManager.LogLevel is set to Developer
/// Note: This test does not require any clients, but should not impact this
/// particular test if new tests are added to this class that do require clients
/// </summary>
[UnityTest]
public IEnumerator ValidateNoSpam()
{
m_AllowServerToStart = true;
var objectToTest = new GameObject();
var simpleNetworkBehaviour = objectToTest.AddComponent<SimpleNetworkBehaviour>();
// Now just start the Host
yield return StartServerAndClients();
// set the log level to developer
m_ServerNetworkManager.LogLevel = LogLevel.Developer;
// The only valid condition for this would be if the NetworkBehaviour is spawned.
simpleNetworkBehaviour.IsSpawned = true;
// Verify the warning gets logged under normal conditions
var isNull = simpleNetworkBehaviour.NetworkObject == null;
LogAssert.Expect(LogType.Warning, $"[Netcode] Could not get {nameof(NetworkObject)} for the {nameof(NetworkBehaviour)}. Are you missing a {nameof(NetworkObject)} component?");
var networkObjectToTest = objectToTest.AddComponent<NetworkObject>();
networkObjectToTest.NetworkManagerOwner = m_ServerNetworkManager;
networkObjectToTest.Spawn();
// Assure no log messages are logged when they should not be logged
isNull = simpleNetworkBehaviour.NetworkObject != null;
LogAssert.NoUnexpectedReceived();
networkObjectToTest.Despawn();
Object.Destroy(networkObjectToTest);
}
/// <summary>
/// This validates the fix for when a child GameObject with a NetworkBehaviour
/// is deleted while the parent GameObject with a NetworkObject is spawned and
/// is not deleted until a later time would cause an exception due to the
/// NetworkBehaviour not being removed from the NetworkObject.ChildNetworkBehaviours
/// list.
/// </summary>
[UnityTest]
public IEnumerator ValidateDeleteChildNetworkBehaviour()
{
m_AllowServerToStart = true;
yield return s_DefaultWaitForTick;
// Now just start the Host
yield return StartServerAndClients();
var parentObject = new GameObject();
var childObject = new GameObject();
childObject.transform.parent = parentObject.transform;
var parentNetworkObject = parentObject.AddComponent<NetworkObject>();
childObject.AddComponent<SimpleNetworkBehaviour>();
parentNetworkObject.Spawn();
yield return s_DefaultWaitForTick;
// Destroy the child object with child NetworkBehaviour
Object.Destroy(childObject);
yield return s_DefaultWaitForTick;
// Assure no log messages are logged when they should not be logged
LogAssert.NoUnexpectedReceived();
// Destroy the parent object which should not cause any exceptions
// (validating the fix)
Object.Destroy(parentObject);
}
}
}