Raise event - custom type not found - passing a list of vectors

Hello, I'm trying to pass two Vector2 lists using the raise event photon function.

But I get this error:

Write failed. Custom type not found: System.Collection.Generic.List[Vector2]

I saw on this solution: https://forum.photonengine.com/discussion/16726/exception-write-failed-custom-type-not-found-unityengine-transform that I should split the list to the variable but this is impossible since the list size.

This is my code:

Just to understand I'm creating a random road and want to send the corners and the connection between the corners to the players.

    private void OnEnable(){

        PhotonNetwork.NetworkingClient.EventReceived += NetworkingClient_EvenetReceived;
    }
    private void OnDisable(){
        PhotonNetwork.NetworkingClient.EventReceived -= NetworkingClient_EvenetReceived;
    }
    private void NetworkingClient_EvenetReceived(EventData obj){

        if(obj.Code == 1){
            object[] road_data = (object[])obj.CustomData;
            RoadCreator road_creator = GameObject.Find("Roads").GetComponent<RoadCreator>();
            road_creator.CreateRoads();
            road_creator.Dots = (List<Vector2>)road_data[0];
            road_creator.Connections = (List<Vector2Int>)road_data[1];
        }
    }

And this is the code on another script:

        RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.All }; // You would have to set the Receivers to All in order to receive this event on the local client as well

        GameObject road_obj=  GameObject.Find("Roads");
        RandomRoad random_road = road_obj.GetComponent<RandomRoad>();
        random_road.SpawnRandomRoads();
        RoadCreator road_creator = road_obj.GetComponent<RoadCreator>();
        object[] road_data = new object[] {road_creator.Dots, road_creator.Connections};
        PhotonNetwork.RaiseEvent(1, road_data, raiseEventOptions, SendOptions.SendReliable);


Best Answer

  • Itay
    Itay
    Answer ✓

    My problem was fixed by changing the list to an array using the theList.ToArray()

    *note I had to replace the Vector2int array with a vector2 array because I couldn't pass that in either

Answers

  • I am not sure this helps, but perhaps you could instead send each vector one by one in a for loop (maybe with additional arguments of its index, and the total size of the list) and add them to a list of vectors on every client.

    Once the list size reaches the total size received in the event, you could sort the list (if necessary) and set the road connections an dots with your RoadCreator class...

    I also don't know if you can pass Vectors to Photon Events, if not you could pass the X, Y and Z values instead...

  • Itay
    Itay
    Answer ✓

    My problem was fixed by changing the list to an array using the theList.ToArray()

    *note I had to replace the Vector2int array with a vector2 array because I couldn't pass that in either