Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

SyncVar updating on host from network message unexpectedly

Discussion in 'Multiplayer' started by playeveryware, Jan 10, 2019.

  1. playeveryware

    playeveryware

    Joined:
    Aug 10, 2017
    Posts:
    31
    I have a SyncVar called intsPack that gets changed unexpectedly on the host. This happens during the process of the first client connecting to the host and spawning. The SpawnFinished message gets sent from the host just before this in the log. It may be worth nothing that I'm not using network manager because we need to use a different matchmaking service. It is my understanding that SyncVars are only sent from the server to clients. So why would the host ever get an update to a SyncVar, since the host would be the one who would have to change it to trigger the update? I've included the log of this happening down below. ClientScene::OnUpdateVarsMessage 2 channel:1 seems to be what updates the SyncVar. The NetID of the object in question here is 2, but the NetworkBehaviour is not on channel 1. In fact, we have no NetworkBehaviours on channel 1 in our game. Just after this message, it prints from the hook on the SyncVar that this change is occuring.


    Code (CSharp):
    1.     [SyncVar(hook = "OnChangeIntspack")]public UInt64 intsPack;
    2.  
    3.     public void OnChangeIntspack(UInt64 newValue)
    4.     {
    5.         if(agent && agent.name == "PlayerrX")
    6.             Debug.LogError("Intspack changed from: " + intsPack + " to: " + newValue);
    7.  
    8.         intsPack = newValue;
    9.     }
    This prints out twice, I don't know why. This behavior still happens without this hook, I only added it to help debug. Then after that, the normal debug output for SyncVars prints and verifies the change again. No where in my code is this SyncVar getting set to 0, on the client or the host. I do not know where this is getting triggered from. I cannot link the full project, and I have not been able to reproduce this in a sample yet.

    ClientScene::OnUpdateVarsMessage 2 channel:1
    UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:Log(Object)
    UnityEngine.Networking.ClientScene:OnUpdateVarsMessage(NetworkMessage)
    UnityEngine.Networking.NetworkMessageDelegate:Invoke(NetworkMessage)
    UnityEngine.Networking.NetworkConnection:InvokeHandler(NetworkMessage)
    UnityEngine.Networking.LocalClient:processInternalMessages()
    UnityEngine.Networking.LocalClient:Update()
    UnityEngine.Networking.NetworkClient:UpdateClients()
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

    (Filename: .\Runtime/Export/Debug.bindings.h Line: 43)

    03:27:54.225: Intspack changed from: 1657326861895794688 to: 0
    UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:LogError(Object)
    Debug:LogError(Object, Object)
    ObjectMult:OnChangeIntspack(UInt64)
    ObjectMult:OnDeserialize(NetworkReader, Boolean)
    ObjectMultAgent:OnDeserialize(NetworkReader, Boolean)
    UnityEngine.Networking.NetworkIdentity:OnUpdateVars(NetworkReader, Boolean)
    UnityEngine.Networking.ClientScene:OnUpdateVarsMessage(NetworkMessage)
    UnityEngine.Networking.NetworkMessageDelegate:Invoke(NetworkMessage)
    UnityEngine.Networking.NetworkConnection:InvokeHandler(NetworkMessage)
    UnityEngine.Networking.LocalClient:processInternalMessages()
    UnityEngine.Networking.LocalClient:Update()
    UnityEngine.Networking.NetworkClient:UpdateClients()
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

    (Filename: .\Runtime/Export/Debug.bindings.h Line: 43)

    03:27:54.228: Intspack changed from: 1657326861895794688 to: 0
    UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:LogError(Object)
    Debug:LogError(Object, Object)
    ObjectMult:OnChangeIntspack(UInt64)
    ObjectMult:set_NetworkintsPack(UInt64)
    ObjectMult:OnChangeIntspack(UInt64)
    ObjectMult:OnDeserialize(NetworkReader, Boolean)
    ObjectMultAgent:OnDeserialize(NetworkReader, Boolean)
    UnityEngine.Networking.NetworkIdentity:OnUpdateVars(NetworkReader, Boolean)
    UnityEngine.Networking.ClientScene:OnUpdateVarsMessage(NetworkMessage)
    UnityEngine.Networking.NetworkMessageDelegate:Invoke(NetworkMessage)
    UnityEngine.Networking.NetworkConnection:InvokeHandler(NetworkMessage)
    UnityEngine.Networking.LocalClient:processInternalMessages()
    UnityEngine.Networking.LocalClient:Update()
    UnityEngine.Networking.NetworkClient:UpdateClients()
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

    (Filename: .\Runtime/Export/Debug.bindings.h Line: 43)

    SetSyncVar ObjectMultAgent bit [1] 1657326861895794688->0
    UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:Log(Object)
    UnityEngine.Networking.NetworkBehaviour:SetSyncVar(UInt64, UInt64&, UInt32)
    ObjectMult:set_NetworkintsPack(UInt64)
    ObjectMult:OnChangeIntspack(UInt64)
    ObjectMult:set_NetworkintsPack(UInt64)
    ObjectMult:OnChangeIntspack(UInt64)
    ObjectMult:OnDeserialize(NetworkReader, Boolean)
    ObjectMultAgent:OnDeserialize(NetworkReader, Boolean)
    UnityEngine.Networking.NetworkIdentity:OnUpdateVars(NetworkReader, Boolean)
    UnityEngine.Networking.ClientScene:OnUpdateVarsMessage(NetworkMessage)
    UnityEngine.Networking.NetworkMessageDelegate:Invoke(NetworkMessage)
    UnityEngine.Networking.NetworkConnection:InvokeHandler(NetworkMessage)
    UnityEngine.Networking.LocalClient:processInternalMessages()
    UnityEngine.Networking.LocalClient:Update()
    UnityEngine.Networking.NetworkClient:UpdateClients()
    UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
     
  2. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Set a breakpoint on the syncvar and see what changes it
     
  3. playeveryware

    playeveryware

    Joined:
    Aug 10, 2017
    Posts:
    31
    I can't connect the debugger on the platform that I'm building for. And my network code does not run on PC. So unfortunately, no breakpoints for me.