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.

Question NetworkList (Netcode for gameObjects)

Discussion in 'Documentation' started by abbouhya, Feb 10, 2023.

  1. abbouhya


    Feb 1, 2023

    I've been trying to learn unity netcode lately, and I find it very easy and fascinating.
    And I have a small question for people with more experience with it.

    I'm trying to find a way to create a list of player class objects to store specific data about every player on my game as follows:

    private NetworkList<Player> playerList;

    void awake(){
    playerList = new NetworkList<Player>();

    However, I keep getting the error : The type 'Player' must be a non-nullable value type.

    While reading through unity documentation I found that they used as an example a very similar code:

    private NetworkList<AreaWeaponBooster> TeamAreaWeaponBoosters;

    void Awake()
    TeamAreaWeaponBoosters = new NetworkList<AreaWeaponBooster>();

    here's the link of the documentation :

    So I can't seem to understand how is my code any different. Can I make the list somehow non nullable? otherwise, is there an easy way to communicate specefic data to each player like hp, mana etc.. without getting lost in too much indexing.

  2. Sean2212


    Jun 9, 2017
    Make sure the type you're using in the NetworkList is a struct (not a class). AreaWeaponBooster is a struct.