Skip to content

Commit

Permalink
fix: NetworkTransform Mixed Unreliable & Reliable Order of Operations (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
NoelStephensUnity authored Dec 5, 2023
1 parent 1495e68 commit 13d1f8c
Show file tree
Hide file tree
Showing 20 changed files with 6,503 additions and 2,944 deletions.
3 changes: 3 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Fixed

- Fixed issue where a teleport state could potentially be overridden by a previous unreliable delta state. (#2777)
- 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)
- 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)
- 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)
- 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)

### Changed

- Changed `NetworkTransform.SetState` (and related methods) now are cumulative during a fractional tick period and sent on the next pending tick. (#2777)
- `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)
- 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)
- Changed `NetworkTransform` authoritative instance tick registration so a single `NetworkTransform` specific tick event update will update all authoritative instances to improve perofmance. (#2713)
Expand Down
245 changes: 167 additions & 78 deletions com.unity.netcode.gameobjects/Components/NetworkTransform.cs

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,12 @@ protected virtual void OnInlineSetup()
public IEnumerator SetUp()
{
VerboseDebug($"Entering {nameof(SetUp)}");

NetcodeLogAssert = new NetcodeLogAssert();
if (m_EnableTimeTravel)
{
// Setup the frames per tick for time travel advance to next tick
ConfigureFramesPerTick();
}
if (m_SetupIsACoroutine)
{
yield return OnSetup();
Expand Down Expand Up @@ -1544,8 +1548,42 @@ protected static void TimeTravel(double amountOfTimeInSeconds, int numFramesToSi
}
}

protected virtual uint GetTickRate()
{
return k_DefaultTickRate;
}

protected virtual int GetFrameRate()
{
return Application.targetFrameRate == 0 ? 60 : Application.targetFrameRate;
}

private int m_FramesPerTick = 0;
private float m_TickFrequency = 0;

/// <summary>
/// Recalculates the <see cref="m_TickFrequency"/> and <see cref="m_FramesPerTick"/> that is
/// used in <see cref="TimeTravelAdvanceTick"/>.
/// </summary>
protected void ConfigureFramesPerTick()
{
m_TickFrequency = 1.0f / GetTickRate();
m_FramesPerTick = Math.Max((int)(m_TickFrequency / GetFrameRate()), 1);
}

/// <summary>
/// Helper function to time travel exactly one tick's worth of time at the current frame and tick rates.
/// This is NetcodeIntegrationTest instance relative and will automatically adjust based on <see cref="GetFrameRate"/>
/// and <see cref="GetTickRate"/>.
/// </summary>
protected void TimeTravelAdvanceTick()
{
TimeTravel(m_TickFrequency, m_FramesPerTick);
}

/// <summary>
/// Helper function to time travel exactly one tick's worth of time at the current frame and tick rates.
/// ** Is based on the global k_DefaultTickRate and is not local to each NetcodeIntegrationTest instance **
/// </summary>
public static void TimeTravelToNextTick()
{
Expand All @@ -1555,7 +1593,6 @@ public static void TimeTravelToNextTick()
{
frameRate = 60;
}

var frames = Math.Max((int)(timePassed / frameRate), 1);
TimeTravel(timePassed, frames);
}
Expand Down
Loading

0 comments on commit 13d1f8c

Please sign in to comment.