Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question about SyncVars and Unet sample games

Discussion in 'UNet' started by UnbreakableOne, Oct 31, 2015.

  1. UnbreakableOne

    UnbreakableOne

    Joined:
    Nov 16, 2013
    Posts:
    168
    Hi,

    In Invaders sample game I've seen this in PlayerControl.cs file:

    Code (csharp):
    1.  
    2.   [Command]
    3.    void CmdShoot()
    4.    {
    5.      if (!alive)
    6.        return;
    7.        
    8.      if (myBullet == null)
    9.      {
    10.        myBullet = (GameObject)GameObject.Instantiate(bulletPrefab, transform.position + Vector3.up, Quaternion.identity);
    11.        myBullet.GetComponent<PlayerBullet>().owner = this;
    12.        NetworkServer.Spawn(myBullet);
    13.      }
    14.    }
    As you can see it's setting "owner" property of PlayerBullet component but "owner" does not have SyncVar attribute. So my question is how this data change is propagated across the network?

    Thanks
     
  2. SpeakUpGames

    SpeakUpGames

    Joined:
    Nov 25, 2014
    Posts:
    56
    I haven't seen the invaders game, but I would assume in this case that any time they check the bullet owner, it's on the server. Any bullets spawned on the client would have the owner as null, but the checks are on the server anyway which is set properly.