Search Unity

Resolved Can't assign to NetworkVariable array

Discussion in 'Netcode for GameObjects' started by shrdlu518, Apr 11, 2022.

  1. shrdlu518

    shrdlu518

    Joined:
    Mar 27, 2020
    Posts:
    6
    I'm trying to create a network array, but I can't assign values.

    I've tried it two ways...
    public NetworkVariable<int> commonCard = new NetworkVariable<int>();
    public NetworkList<int>[] commonDeck = new NetworkList<int>[99];

    ... but when I try to move values ...
    commonCards = i;
    commonDeck = i;

    ... both get the error "Cannot implicitly convert type <int> to Unity.Netcode.NetworkVariable<int>" (or ...NetworkList<int>). Assigning a constant gets the same error.

    This must be simple, but I don't know what to do, and searching Unity documentation generates a lot of "Page Not Found"
    What is the fix for this?

    Thanks for anything that anyone can tell me
     
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    664
    Use NetworkList and use it as you would do a List, .Add, .Count, etc. It has a lot of List's functionality.
     
  3. Ocks

    Ocks

    Joined:
    May 3, 2022
    Posts:
    1
    I know this is a bit late, but you need to use...

    commonCards.Value

    ...instead of just the variable name.