Skip to content

Commit 13d1f8c

Browse files
fix: NetworkTransform Mixed Unreliable & Reliable Order of Operations (#2777)
* fix - This resolves an issue with mixing reliable and unreliable messages that could impact teleporting if a state delta was sent prior to teleporting on the same NetworkTick within the same frame. - The staggered tick for axis sync was not including the current server tick as part of its initial value causing a frame synch every other tick. - Ignoring any new state update that has a tick value lower than the last/old state update when using unreliable deltas. * update - increasing time out period - Did some clean up and fixed some issues with the one at a time NetworkTransformTest. - Renamed m_SetNetworkTransformState to TeleportingNetworkTransformState and made it internal for testing purposes. - When explicitly setting state, it now is cumulative regarding flag states (i.e. it does not send outside of the tick event generated window). - Making explicitly set states persist the exact state at the time it was set in order to assure no additional transform modifications are updated implicitly. - Updated several test projects that still had references to the UNet component which no longer exists in 2021. - Switching from ReliableFragmentedSequenced to ReliableSequenced. * test - Cleaned up the packet loss test and running it at the default tick rate. - Added a test to validate that when teleporting on the same tick and frame that an unreliable delta state update was sent that the teleport state update is deferred to the next tick. - Includes several fixes for issues with NetworkTransform tests and with the initial unreliable delta state update changes. - Condensed the packet loss and standard network transform commonly shared code into a single NetworkTransformBase class. - Added TestMultipleExplicitSetStates test to validate explicitly setting state multiple times within the same fractional tick period will be preserved and propogate out on the next upcoming tick. - Fixed some issues with the TestRotationThresholdDeltaCheck test. - Updated NetcodeIntegrationTest to provide a generic test relative TimeTravelAdvanceTick to assure all tests are operating at their set frame rate and tick values. - Excluding the packet loss test for UTP v2.x.
1 parent 1495e68 commit 13d1f8c

File tree

20 files changed

+6503
-2944
lines changed

20 files changed

+6503
-2944
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ Additional documentation and release notes are available at [Multiplayer Documen
2121

2222
### Fixed
2323

24+
- Fixed issue where a teleport state could potentially be overridden by a previous unreliable delta state. (#2777)
25+
- Fixed issue where `NetworkTransform` was using the `NetworkManager.ServerTime.Tick` as opposed to `NetworkManager.NetworkTickSystem.ServerTime.Tick` during the authoritative side's tick update where it performed a delta state check. (#2777)
2426
- Fixed issue where a parented in-scene placed NetworkObject would be destroyed upon a client or server exiting a network session but not unloading the original scene in which the NetworkObject was placed. (#2737)
2527
- Fixed issue where during client synchronization and scene loading, when client synchronization or the scene loading mode are set to `LoadSceneMode.Single`, a `CreateObjectMessage` could be received, processed, and the resultant spawned `NetworkObject` could be instantiated in the client's currently active scene that could, towards the end of the client synchronization or loading process, be unloaded and cause the newly created `NetworkObject` to be destroyed (and throw and exception). (#2735)
2628
- Fixed issue where a `NetworkTransform` instance with interpolation enabled would result in wide visual motion gaps (stuttering) under above normal latency conditions and a 1-5% or higher packet are drop rate. (#2713)
2729

2830
### Changed
2931

32+
- Changed `NetworkTransform.SetState` (and related methods) now are cumulative during a fractional tick period and sent on the next pending tick. (#2777)
3033
- `NetworkManager.ConnectedClientsIds` is now accessible on the client side and will contain the list of all clients in the session, including the host client if the server is operating in host mode (#2762)
3134
- Changed `NetworkSceneManager` to return a `SceneEventProgress` status and not throw exceptions for methods invoked when scene management is disabled and when a client attempts to access a `NetworkSceneManager` method by a client. (#2735)
3235
- Changed `NetworkTransform` authoritative instance tick registration so a single `NetworkTransform` specific tick event update will update all authoritative instances to improve perofmance. (#2713)

com.unity.netcode.gameobjects/Components/NetworkTransform.cs

Lines changed: 167 additions & 78 deletions
Large diffs are not rendered by default.

com.unity.netcode.gameobjects/Runtime/Messaging/RpcTargets/BaseRpcTarget.cs.meta

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTest.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,12 @@ protected virtual void OnInlineSetup()
305305
public IEnumerator SetUp()
306306
{
307307
VerboseDebug($"Entering {nameof(SetUp)}");
308-
309308
NetcodeLogAssert = new NetcodeLogAssert();
309+
if (m_EnableTimeTravel)
310+
{
311+
// Setup the frames per tick for time travel advance to next tick
312+
ConfigureFramesPerTick();
313+
}
310314
if (m_SetupIsACoroutine)
311315
{
312316
yield return OnSetup();
@@ -1544,8 +1548,42 @@ protected static void TimeTravel(double amountOfTimeInSeconds, int numFramesToSi
15441548
}
15451549
}
15461550

1551+
protected virtual uint GetTickRate()
1552+
{
1553+
return k_DefaultTickRate;
1554+
}
1555+
1556+
protected virtual int GetFrameRate()
1557+
{
1558+
return Application.targetFrameRate == 0 ? 60 : Application.targetFrameRate;
1559+
}
1560+
1561+
private int m_FramesPerTick = 0;
1562+
private float m_TickFrequency = 0;
1563+
1564+
/// <summary>
1565+
/// Recalculates the <see cref="m_TickFrequency"/> and <see cref="m_FramesPerTick"/> that is
1566+
/// used in <see cref="TimeTravelAdvanceTick"/>.
1567+
/// </summary>
1568+
protected void ConfigureFramesPerTick()
1569+
{
1570+
m_TickFrequency = 1.0f / GetTickRate();
1571+
m_FramesPerTick = Math.Max((int)(m_TickFrequency / GetFrameRate()), 1);
1572+
}
1573+
15471574
/// <summary>
15481575
/// Helper function to time travel exactly one tick's worth of time at the current frame and tick rates.
1576+
/// This is NetcodeIntegrationTest instance relative and will automatically adjust based on <see cref="GetFrameRate"/>
1577+
/// and <see cref="GetTickRate"/>.
1578+
/// </summary>
1579+
protected void TimeTravelAdvanceTick()
1580+
{
1581+
TimeTravel(m_TickFrequency, m_FramesPerTick);
1582+
}
1583+
1584+
/// <summary>
1585+
/// Helper function to time travel exactly one tick's worth of time at the current frame and tick rates.
1586+
/// ** Is based on the global k_DefaultTickRate and is not local to each NetcodeIntegrationTest instance **
15491587
/// </summary>
15501588
public static void TimeTravelToNextTick()
15511589
{
@@ -1555,7 +1593,6 @@ public static void TimeTravelToNextTick()
15551593
{
15561594
frameRate = 60;
15571595
}
1558-
15591596
var frames = Math.Max((int)(timePassed / frameRate), 1);
15601597
TimeTravel(timePassed, frames);
15611598
}

0 commit comments

Comments
 (0)