Closed JadenH closed 3 months ago
This might not be the best long-term fix, but I resolved this issue by resetting and initializing LastPacketTick when the server/client starts and stops in TimeManager.cs
:
/// <summary>
/// Called after the local client connection state changes.
/// </summary>
private void ClientManager_OnClientConnectionState(ClientConnectionStateArgs obj)
{
if (obj.ConnectionState != LocalConnectionState.Started)
{
_pingStopwatch.Stop();
ClientUptime = 0f;
//Only reset ticks if also not server.
if (!NetworkManager.IsServerStarted)
{
LocalTick = 0;
Tick = 0;
SetTickRate(TickRate);
}
}
//Started.
else
{
_pingStopwatch.Restart();
}
if (obj.ConnectionState == LocalConnectionState.Started)
{
LastPacketTick.Initialize(this);
}
if (obj.ConnectionState == LocalConnectionState.Stopped)
{
LastPacketTick.Reset();
}
}
/// <summary>
/// Called after the local server connection state changes.
/// </summary>
private void ServerManager_OnServerConnectionState(ServerConnectionStateArgs obj)
{
//If no servers are running.
if (!NetworkManager.ServerManager.AnyServerStarted())
{
ServerUptime = 0f;
Tick = 0;
}
if (obj.ConnectionState == LocalConnectionState.Started)
{
LastPacketTick.Initialize(this);
}
if (obj.ConnectionState == LocalConnectionState.Stopped)
{
LastPacketTick.Reset();
}
}
I tried updating to 4.4.1
and this issue is still present.
Yes, if we do not mark something as resolved we've not yet implemented it. Your fix is very likely the appropriate route to take though. I'll check it out and get the fix in.
Checked out the code, you will want to make sure LPT does not reset if the client or server is connected. The solution is to reset if server state is not started, or if client state is not started and server isnt started.
private void ClientManager_OnClientConnectionState(ClientConnectionStateArgs obj)
{
if (obj.ConnectionState != LocalConnectionState.Started)
{
if (!NetworkManager.IsServerStarted)
LastPacketTick.Reset();
General Unity version: 2022.3.27f1 Fish-Networking version: 4.3.8 Discord link: https://discord.com/channels/424284635074134018/1270893274621546528
Description Clients have an invalid Tick value after their first match. This looks to be due to the
LastPacketTick.Reset
never being called on the client after disconnecting from the first match.The
LastPacketTick
is used in the ParseTimingUpdate to calculate thenextTick
anddifference
:ClientManager updates the LastPacketTick in
ClientManager.cs
:Which makes its way to Update in
EstimatedTick.cs
:Since
RemoteTick
is set to a value from the previous match, it's greater than the newremoteTick
received in the new match.oldTickOption
is set toEstimatedTick.OldTickOption.Discard
, causing the method to return early and not update theLocalTick
orRemoteTick
.There are no references to
LastPacketTick.Reset
in FishNet.EstimatedTick.cs
contains aReset
method that should likely be called upon client disconnect, the same wayPacketTick
andLocalTick
are reset atNetworkConnection.ResetState:449
.Replication Steps to reproduce the behavior:
Note: Issue resolves once the server tick surpasses the incorrect client tick.
Expected behavior Client tick should be approximately equal to the server tick.
Screenshots The screenshot shows some debug UI at the top right-hand side of the screen, showing the value of
TimeManager.Tick
, and the values withinLastPacketTick
.