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

How do I keep a class in sync?

Discussion in 'Multiplayer' started by maikklein, Jul 20, 2015.

  1. maikklein

    maikklein

    Joined:
    Jun 16, 2015
    Posts:
    33
    Code (CSharp):
    1. public class PlayerController : NetworkBehaviour {
    2.     Player player;
    3. ....
    4.     void Start()
    5.     {
    6.         if (isServer)
    7.         {
    8.             playerObject = (GameObject)Instantiate(playerPrefab, playerPrefab.transform.position, playerPrefab.transform.rotation);
    9.             player = playerObject.GetComponent<Player>();
    10.             player.playerController = this;
    11.             NetworkServer.Spawn(playerObject);
    12.         }
    13. ...
    14. }
    Now I want to access 'player' on the client, how do I do this?

    If I mark player with a syncvar I get

    Do I have to write a custom serializer for this?