Closed
Description
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.