FishNet icon indicating copy to clipboard operation
FishNet copied to clipboard

SyncType does not send changes when NetworkObject is despawned on the same tick it's spawned

Open ooonush opened this issue 1 year ago • 4 comments

General Unity version: 6000.0.3 Fish-Networking version: 4.3.5

Description SyncType does not send changes to client when NetworkObject is despawned on the same tick it's spawned.

Replication

  1. Place the NetworkObject with the TestSpawner component on the scene:
public class TestSpawner : NetworkBehaviour
{
    [SerializeField] private TestNetworkBehaviour _prefab;

    public override void OnStartClient()
    {
        if (IsHostInitialized)
        {
            NetworkObject no = NetworkManager.GetPooledInstantiated(_prefab.NetworkObject, true);
            Spawn(no);
            // and despawn this:
            Despawn(no);
        }
    }
}
  1. Create a NetworkObject prefab with a TestNetworkBehaviour component:
public class TestNetworkBehaviour : NetworkBehaviour
{
    private readonly SyncVar<int> _syncVar = new();

    public override void OnStartServer()
    {
        Debug.Log("OnStartServer");
        _syncVar.Value = 10;
    }

    public override void OnStartClient()
    {
        Debug.Log("OnStartClient " + _syncVar.Value);
    }
}
  1. Start server
  2. Start other clients
  3. Start client-host

Expected behavior

On client started SyncType should be 10, not 0. Since OnStartClient is being called, the SyncTypes should also be synchronized. This is a problem for me when the projectile is despawned on the same tick it`s spawned.

Screenshots image

ooonush avatar Jun 06 '24 08:06 ooonush

What works for me is this despawn method:

private uint _tickSpawned;
private NetworkObject _no;

public override void OnStartClient()
{
    if (IsHostInitialized)
    {
        _no = NetworkManager.GetPooledInstantiated(_prefab.NetworkObject, true);
        Spawn(_no);
        _tickSpawned = TimeManager.Tick;
    }
}

private void TimeManager_OnTick()
{
    if (_no && TimeManager.Tick > _tickSpawned + 2)
    {
        Despawn(_no);
        _no = null;
    }
}

That is, I have to do a check for TimeManager.Tick > _tickSpawned + 2.

ooonush avatar Jun 06 '24 08:06 ooonush

For clients-only the check TimeManager.Tick > _tickSpawned works. But on the client-host I have to check TimeManager.Tick > _tickSpawned + 2, which is not very elegant.

ooonush avatar Jun 06 '24 09:06 ooonush

I'm fairly certain your desired setup should work without any changes. There's even code specific to sending pending SyncType data through on despawn for this exact scenario.

I'll make this is a bug today and take a look, most likely something small.

On Thu, Jun 6, 2024, 5:07 AM Alven @.***> wrote:

For clients-only the check TimeManager.Tick > _tickSpawned works. But on the client-host I have to check TimeManager.Tick > _tickSpawned + 2, which is not very elegant.

— Reply to this email directly, view it on GitHub https://github.com/FirstGearGames/FishNet/issues/692#issuecomment-2151785262, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGPJC3RIGMIPJTF4KJN6QVTZGARGNAVCNFSM6AAAAABI4HYCVOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJRG44DKMRWGI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

FirstGearGames avatar Jun 06 '24 09:06 FirstGearGames

Do not have time to get this into 4.3.6 but making it high priority for 4.3.7

FirstGearGames avatar Jul 01 '24 13:07 FirstGearGames

Priority updated to after delta serializers for prediction. The serializers are close to being finished so I'd like to finish them up first.

FirstGearGames avatar Jul 25 '24 22:07 FirstGearGames

Resolved in 4.4.0

FirstGearGames avatar Aug 03 '24 22:08 FirstGearGames