Serialize Array of Vector3 and Quaternion

Hello, i’m trying to serialize this structs:

public struct PlayerPositionData : INetworkSerializable, IEquatable<PlayerPositionData>
{
    public int numeroAncora;
    public Vector3[] posizioni;
    public Quaternion[] rotazioni;

    public PlayerPositionData(int numeroAnc, Vector3[] posiz, Quaternion[] rotaz)
    {
        numeroAncora = numeroAnc;
        posizioni = posiz;
        rotazioni = rotaz;
    }


    public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
    {
        serializer.SerializeValue(ref numeroAncora);

        //SERIALIZZO ARRAY POSIZIONI
        int length = 0;
        if (!serializer.IsReader)
        {
            length = posizioni.Length;
        }

        serializer.SerializeValue(ref length);

        // Array
        if (serializer.IsReader)
        {
            posizioni = new Vector3[length];
        }

        for (int n = 0; n < length; ++n)
        {
            serializer.SerializeValue(ref posizioni[n]);
        }


      
        //SERIALIZZO ARRAY ROTAZIONI
        if (!serializer.IsReader)
        {
            length = rotazioni.Length;
        }

        serializer.SerializeValue(ref length);

        // Array
        if (serializer.IsReader)
        {
            rotazioni = new Quaternion[length];
        }

        for (int n = 0; n < length; ++n)
        {
            serializer.SerializeValue(ref rotazioni[n]);
        }
    }

    public bool Equals(PlayerPositionData other)
    {
        return posizioni.Length == other.posizioni.Length && numeroAncora == other.numeroAncora;
    }
}
public struct PlayerData : INetworkSerializable, IEquatable<PlayerData>
{
    public ulong idRete;
    public int numeroPlayer;
    public PlayerPositionData posizioni;

    public PlayerData(ulong idRet, int payerN, PlayerPositionData posiz)
    {
        idRete = idRet;
        numeroPlayer = payerN;
        posizioni = posiz;
    }


    public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
    {
        serializer.SerializeValue(ref idRete);
        serializer.SerializeValue(ref numeroPlayer);

        posizioni.NetworkSerialize(serializer);
    }

    public bool Equals(PlayerData other)
    {
        return idRete == other.idRete;
    }
}

in this way:

private NetworkList<PlayerData> datiPlayers = new NetworkList<PlayerData>();

but i recive this error:
error CS8377: The type 'PlayerData' 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<T>'

why?

1 Like

why do you keep ignoring these threads unity

1 Like

Bump - I’m stuck in the same place.

@luke-unity Any ideas here?

Apologies - please disregard. The moment I submitted it I figured out that I hadn’t converted one of my classes to a struct. :frowning: