Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LocalTick breaks "only increment" promise when connecting the host client #559

Closed
TsFreddie opened this issue Nov 25, 2023 · 7 comments
Closed
Labels
Bug Something isn't working Resolved Pending Release

Comments

@TsFreddie
Copy link
Contributor

TsFreddie commented Nov 25, 2023

General
Unity version: 2022.3.8f
Fish-Networking version: 4.0.3 & 3.11.10

Description
When host client connects, both LocalTick and Tick value (since they are the same value when server is running) decreases.
Although I believe "Tick" shouldn't decrease either in server, LocalTick did promise that in the XML doc.

Replication

  1. Attach the following script to an empty scene with the example NetworkManager prefab
  2. Run the scene
  3. Click "Server"
  4. Click "Client"
using FishNet;
using FishNet.Transporting;
using UnityEngine;

public class TickCheck : MonoBehaviour
{
    private long _lastTick = -1;
    private bool _initialized;

    private void Update()
    {
        if (!_initialized)
        {
            var serverManager = InstanceFinder.ServerManager;
            if (serverManager)
            {
                serverManager.OnServerConnectionState += OnServerConnectionState;
                _initialized = true;
            }
        }
    }
    
    private void OnServerConnectionState(ServerConnectionStateArgs args)
    {
        switch (args.ConnectionState)
        {
        case LocalConnectionState.Started:
            InstanceFinder.TimeManager.OnTick += OnTick;
            break;
        case LocalConnectionState.Stopping:
            InstanceFinder.TimeManager.OnTick -= OnTick;
            _lastTick = -1;
            break;
        }
    }

    private void OnTick()
    {
        if (_lastTick == -1)
        {
            _lastTick = InstanceFinder.TimeManager.LocalTick;
            return;
        }
        
        if (InstanceFinder.TimeManager.LocalTick - _lastTick != 1)
        {
            var expectedTick = _lastTick + 1;
            Debug.LogError($"Expecting tick: {expectedTick}, Unexpected tick: {InstanceFinder.TimeManager.LocalTick}");
        }
        
        _lastTick = InstanceFinder.TimeManager.LocalTick;
    }
}

Expected behavior
The LocalTick (or Tick in server) shouldn't decrease or stay the same during two different OnTick/OnPreTick/OnPostTick calls

@TsFreddie TsFreddie changed the title LocalTick breaks "only increment" promise when connecting the host client for the first time LocalTick breaks "only increment" promise when connecting the host client Nov 25, 2023
@FirstGearGames
Copy link
Owner

FirstGearGames commented Nov 25, 2023 via email

@FirstGearGames
Copy link
Owner

After reviewing your example more thoroughly(on desktop) I see that you are disconnecting a socket. The tick is supposed to reset when the socket closes. When clientHost the client uses the servers tick since it is the server, so tick will reset when clientOnly or when server socket changes.

In other words, seems to be working properly.

@TsFreddie
Copy link
Contributor Author

Is connecting a client as host disconnecting the socket?

@FirstGearGames
Copy link
Owner

No, that should not reset Tick. If that's happening it is indeed a bug.

@TsFreddie
Copy link
Contributor Author

TsFreddie commented Nov 25, 2023

The testing code listening LocalConnectionState is just to reset the test when Server stops. The reproduceable steps does not involve stopping the server.

Click Server -> Click Client -> Mismatched tick

@FirstGearGames
Copy link
Owner

I was able to reproduce. Thanks!

@FirstGearGames FirstGearGames added the Bug Something isn't working label Nov 25, 2023
@FirstGearGames
Copy link
Owner

Here's the line that needs correction... Inside ClientManager.cs find
networkManager.TimeManager.Tick = networkManager.TimeManager.LastPacketTick;
and add a not IsServer conditional, like so...

            //Only do this if not also server.
            if (!networkManager.IsServer)
                networkManager.TimeManager.Tick = networkManager.TimeManager.LastPacketTick;

FirstGearGames added a commit that referenced this issue Nov 27, 2023
- Fixed clientHost setting Tick value overwriting servers value. (#559)(#560)
- Fixed NetworkTransform sending repeatedly under certain conditions, bug introduced in 3.11.11.
- Fixed key already exist error when multiple classes with SyncTypes inherited the same NetworkBehaviour.
- Improved logging message when a RPC or SyncType index has already been registered.
- Changed Release Mode and Development Mode to Stable and Beta.
- Changed RigidbodyPauser parenting fix is no longer in Beta.
- Fixed Version 3 to Version 4 SyncType validator causing editor error for abstract NetworkBehaviours while on IL2CPP.
FirstGearGames added a commit that referenced this issue Nov 27, 2023
- Fixed clientHost setting Tick value overwriting servers value.(#559)(#560)
- Fixed NetworkTransform sending repeatedly under certain conditions, bug introduced in 3.11.11.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Resolved Pending Release
Projects
None yet
Development

No branches or pull requests

2 participants