FirstGearGames / FishNet

FishNet: Unity Networking Evolved.
Other
1.38k stars 148 forks source link

SyncTimer out of sync with the server #768

Closed SimEof closed 1 month ago

SimEof commented 2 months ago

Important

If General, Description, and Replication are not completed the issue will be closed immediately.

General Unity version: 2022.3.40.f1 Fish-Networking version: 4.4.4 Pro

Description SyncTimer OnChange not called for clients.

Replication Steps to reproduce the behavior:

  1. Create a simple NetworkObject with NetworkBehaviour that has SyncTimer;
  2. Make server start this timer with duration in OnStartNetwork method;
  3. Join with a client;
  4. When client joins and subscribes to timers OnChange there is no callback with operation SyncTimerOperation.Start. Also debugging the timers remaining value it is out of sync on clients side.

Expected behavior When a new client joins the host, subscribes to SyncTimer OnChange and SyncTimer initialy receives data from server - client receives an event with current state of the timer and timer is in sync with the server.

FirstGearGames commented 2 months ago

This seems to be partially working.

The callbacks are failing at the very beginning as you said. But the values are synchronizing and printing properly.

using FishNet.Object;
using FishNet.Object.Synchronizing;
using UnityEngine;

/// <summary>
/// Test by starting the server in one editor, then the client in another. Ensure that syncTimer value is synchronized.
///
/// Also reported that callback does not work when client subscribes in OnStartNetwork. Test in awake, and in OnStartNetwork.
/// </summary>
public class SyncTimer_Sync_Test : NetworkBehaviour
{
    private void Awake()
    {
        _st.OnChange += StOnOnChange;
    }

    private readonly SyncTimer _st = new();

    public override void OnStartServer()
    {
        _st.StartTimer(15f);
    }

    public override void OnStartNetwork()
    {
        Debug.Log($"Network Start. Remaining {_st.Remaining}.");
    }

    private void StOnOnChange(SyncTimerOperation op, float prev, float next, bool asServer)
    {
        Debug.Log($"Change callback received. Op {op}. Prev {prev}. Next {next}. AsServer {asServer}.");
    }

    private void Update()
    {
        _st.Update();
    }
}

Setting as a bug to resolve callbacks.

Note: I subscribed in Awake for testing - disregard me doing so.

FirstGearGames commented 2 months ago

Won't make it into 4.4.6, probably next release.

FirstGearGames commented 1 month ago

I believe this is resolved in 4.4.8 (pending release soon). I fixed a different SyncTimer bug and am getting all the callbacks now on this test as well.

image