hey guys i’m having a issue trying to serialize a list of networkID’s i believe i followed the documentation correctly however in the editor i am getting 2 errors
Assets\Scripts\mainmenu\LobbyManager.cs(263,9): error - GiveLobbyListToClientRPC - Don’t know how to serialize System.Collections.Generic.List1<System.UInt64>. RPC parameter types must either implement INetworkSerializeByMemcpy or INetworkSerializable. If this type is external and you are sure its memory layout makes it serializable by memcpy, you can replace System.Collections.Generic.List
1<System.UInt64> with ForceNetworkSerializeByMemcpy1<System.Collections.Generic.List
1<System.UInt64>>, or you can create extension methods for FastBufferReader.ReadValueSafe(this FastBufferReader, out System.Collections.Generic.List1<System.UInt64>) and FastBufferWriter.WriteValueSafe(this FastBufferWriter, in System.Collections.Generic.List
1<System.UInt64>) to define serialization for this type.
and then the same error but for deserialization.
i believe these are the relevant codeblocks
private List<ulong> networkLobbyObjects = new();
public struct NetworkLobbyObjectSerializer : INetworkSerializable
{
public List<ulong> myList;
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
int count = 0;
if (!serializer.IsReader)
{
count = myList.Count;
}
serializer.SerializeValue(ref count);
if (serializer.IsReader)
{
myList = new(count);
}
for (int i = 0; i < count; i++)
{
ulong objectToSerialize = myList[i];
serializer.SerializeValue(ref objectToSerialize);
myList[i] = objectToSerialize;
}
}
}
and then also these two methods
public async void CreateLobby(GameObject sentLobbyContainer)
{
if (NetworkManager.IsServer == true)
{
try
{
Debug.Log("container sent = " + sentLobbyContainer.name);
string lobbyName = sentLobbyContainer.name;
int maxPlayers = 1;
CreateLobbyOptions lobbyOptions = new();
lobbyOptions.Data = new();
DataObject lobbyStateData = new(DataObject.VisibilityOptions.Public, "notReady");
lobbyOptions.Data.Add("LobbyState", lobbyStateData);
Player player = GetPlayer();
lobbyOptions.Player = player;
lobbyOptions.IsPrivate = false;
Lobby myLobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, lobbyOptions);
currentActiveLobbies.Add(myLobby);
//lobbyCount++;
hostLobby = myLobby;
joinedLobby = hostLobby;
Debug.Log("hostID of this lobby is " + myLobby.HostId);
//MultiLineDebug.Log("new lobby created as " + myLobby.Name, "maxPlayer count is " + myLobby.MaxPlayers, "lobbyId: " + myLobby.Id, "LobbyCode: " + myLobby.LobbyCode);
}
catch (LobbyServiceException error)
{
Debug.LogError(error);
}
}
else
{
NetworkObject theSentLobbyContainer = sentLobbyContainer.GetComponent<NetworkObject>();
ulong networkID = theSentLobbyContainer.NetworkObjectId;
networkLobbyObjects.Add(networkID);
Debug.Log("client #" + OwnerClientId + " is sending a server rpc");
GiveLobbyToServerRPC(networkID);
}
}
[ServerRpc(RequireOwnership = false)]
private void GiveLobbyToServerRPC(ulong networkID)
{
GameObject sentLobbyContainer = NetworkManager.Singleton.SpawnManager.SpawnedObjects[networkID].gameObject;
Debug.Log("server has received " + sentLobbyContainer.name + " from client");
CreateLobby(sentLobbyContainer);
}
private async void handleActiveLobbiesList()
{
if (updateRequestFrequency < updateRequestFrequencyMax)
{
updateRequestFrequency += Time.deltaTime;
}
else
{
updateRequestFrequency = 0;
if (NetworkManager.Singleton.IsServer == true)
{
try
{
QueryResponse lobbiesQuery = await Lobbies.Instance.QueryLobbiesAsync();
Debug.Log("Lobbies found: " + lobbiesQuery.Results.Count);
currentActiveLobbies = lobbiesQuery.Results;
lobbyCount = currentActiveLobbies.Count;
}
catch (LobbyServiceException error)
{
Debug.LogError(error);
}
}
if (previousLobbyCount != lobbyCount)
{
previousLobbyCount = lobbyCount;
NetworkLobbyObjectSerializer networkLobbyObjectSerializer = new();
networkLobbyObjectSerializer.myList = networkLobbyObjects;
List<ulong> serializedList = networkLobbyObjectSerializer.myList;
GiveLobbyListToClientRPC(serializedList);
}
}
}
[ClientRpc]
private void GiveLobbyListToClientRPC(List<ulong> _networkLobbyObject)
{
Debug.Log("GiveLobbyListToClientRPC sent");
}