Search Unity

Please help sharing data on NetworkBehaviours

Discussion in 'Multiplayer' started by thedude22, Sep 2, 2017.

  1. thedude22

    thedude22

    Joined:
    Jun 26, 2016
    Posts:
    9
    Im trying to make a strategy game where each player will be in control of a number of unit prefabs. So I have a PlayerAssets script that contains a list of GameUnit, where both classes derive from NetworkBehaviour. To make my code more modular I want to separate out the player input controls onto a separate script, PlayerInput. I grab the list of gameunits from PlayerAssets into PlayerInput in the Awake function via:
    Code (csharp):
    1.  
    2. List<GameUnit> myUnits = GetComponent<PlayerAssets>().myUnits;
    3.  
    but the results are not the same. The list shows up as empty on the input script, when it has a unit in it in the assets script. Does anyone know why this would happen? This is a reference variable. They should always be the same. Is the list serialized when I retrieve it? Why would that happen? These are not even networked variables, just local client bookkeeping. I can always do everything in one script, but I'd like to keep things more modular with shorter scripts.
     
  2. thedude22

    thedude22

    Joined:
    Jun 26, 2016
    Posts:
    9
    Nevermind. The timing was just wrong. It wasn't populated on the first frame. Please delete this thread.