Search Unity

Variables are being synced even without SyncVar?

Discussion in 'Multiplayer' started by gaazkam, Aug 29, 2016.

  1. gaazkam

    gaazkam

    Joined:
    Mar 30, 2016
    Posts:
    24
    I was following this tutorial: http://docs.unity3d.com/Manual/UNetSetup.html and I bumped into a weird (to me) thing as soon as I reached the section “Player State (Non-Networked Health”.

    The manual explicitly states that at this point (before adding a SyncVar attribute to the public int health field!) the health is not networked and instead, “If a player shoots another player now, the health goes down on that particular client, but not on other clients”, and also, “Changes to health are being applied everywhere now - independently on the client and host. This allows health o look different for different players”.

    Well, I have to say this is not what I was experiencing... Instead, when I was shooting a player cube on one client, the health bar was going down not only on the active client, but was being depleted identically on the other client as well!

    I am dumbfounded... :( I think I was following the tutorial accurately.

    Unity 5.4.0f3 Personal
     
  2. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,261
    If both clients created the exact same bullet and hit the same target with it, then the health value is the same.

    But due to lag, missed network instructions or other common network issues one client could create a bullet at a different position or direction, not hitting the same target or nothing at all. So on one client the target was hit and the health decreased, while on the other client it still has full health.

    Usually only the server creates bullets, tells other clients to spawn a local copy and then only the server is responsible for calculating player health.