Unity Mirror: Problem with using custom lists in combination with commands that call clientRpcs

136 Views Asked by At

important information:

  • 1 client and 1 host
  • both have a list of objects of a custom class (different lists)
  • task is to add the one of the host in front of the one of the client and to have this version on the client and the host
  • client calls command to start host recieves it and fills in his list and then calls a clientRpc and passes his list on to the client

The last step is the problem: The list that the host fills in in the command is correct (used Debug.Log() to observe) but the list recieved in the parameter on the client has the same length but the content is diffrent the objects are all blank (the variables of the objects have the value null even it wasn't like that on the hosts side).

I have no ideas how to solve the problem but to send the variable values seperated. The problem with this is that the data amount would be to great so that I am looking for a better alternative.

(Sorry for my bad english. If anyone of you speaks german, I can give you a better alternative of the problem in german.) Thanks for your help!

my code:

using Mirror;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Übermittlung : NetworkBehaviour
{
    [SerializeField] private Judoka_speicher Js;

void Start()
    {
        if (isClientOnly) 
        {
            skipframe();
            Debug.Log("Sync-Start(c)");
            liste_synchronisieren_t1_command();
        }
    }

    [Command]
    private void liste_synchronisieren_t1_command() 
    {
        if (isServer && isClient) 
        {
            Debug.Log("Sync_Start(s)");
            List<Judokaklassenhalter.Judoka> judokas = Js.GetJudokas();
            Debug.Log(judokas[0].GetVorname());
            liste_synchronisieren_teil1(judokas);
        }
    }

    [ClientRpc]
    private void liste_synchronisieren_teil1(List<Judokaklassenhalter.Judoka> alteListe) 
    {
        Debug.Log(Js.GetJudokas()[0].GetVorname());
        if (isClientOnly) 
        {
            List<Judokaklassenhalter.Judoka> liste = alteListe;
            Debug.Log("1.Sync-Befehl");
            Debug.Log(liste[0]);
            List<Judokaklassenhalter.Judoka> alteListe2 = Js.addListVorne(alteListe);
            liste_synchronisieren_t2_command(alteListe2);
        }
    }
}
1

There are 1 best solutions below

0
not_actually_finn On BEST ANSWER

The solution that worked for me is to make the variables (strings and ints) in the class of the objects in the list public.