Skip to content

NetworkList<T> initialization and Docs: /versioned_docs/version-1.0.0/advanced-topics/serialization/inetworkserializable.md #1396

Closed
@Falkonio

Description

@Falkonio

I can not initialize NetworkList.

using Unity.Netcode;

    public struct LobbyPlayerState : INetworkSerializable
    {
        public ulong ClientId;
        public string PlayerName;
        public bool IsReady;

        public LobbyPlayerState(ulong clientId, string playerName, bool isReady)
        {
            ClientId = clientId;
            PlayerName = playerName;
            IsReady = isReady;
        }

        public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
        {
            serializer.SerializeValue(ref ClientId);
            serializer.SerializeValue(ref PlayerName);
            serializer.SerializeValue(ref IsReady);
        }
    }

Next I try initialize NetworkList type of LobbyPlayerState:

public class Lobby : NetworkBehaviour
{
      private NetworkList<LobbyPlayerState> lobbyPlayers = new NetworkList<LobbyPlayerState>();
}

And get error:

Severity Code Description Project File Line Suppression State
Error CS8377 The type 'LobbyPlayerState' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'NetworkList'

How can I fix this error and initialize the NetworkList for further use? The instructions lack a more detailed disclosure of this point.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions