can't save playerslist via stream in photon
Hello, When players join it will add the player object to the List i defined which is
public static List<Player> players = new List<Player>();
like this way
players.Add(player);
so the problem is that the new players will get the list with only the players who joins after them
so i decided to use OnPhotonSerializeView like this way
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if(stream.isWriting) {
Debug.Log("writing players");
stream.SendNext(players);
} else {
Debug.Log("Receiving players");
players = (List<Player>)stream.ReceiveNext();
}
}
and added photon view to the gameobject with script like this
i got two problems, first when sending player i get this error
Exception: cannot serialize(): System.Collections.Generic.List`1[Player]
at ExitGames.Client.Photon.Protocol16.Serialize (ExitGames.Client.Photon.StreamBuffer dout, System.Object serObject, Boolean setType) [0x00000] in <filename unknown>:0
at ExitGames.Client.Photon.Protocol16.SerializeObjectArray (ExitGames.Client.Photon.StreamBuffer dout, System.Object[] objects, Boolean setType) [0x00000] in <filename unknown>:0
at ExitGames.Client.Photon.Protocol16.Serialize (ExitGames.Client.Photon.StreamBuffer dout, System.Object serObject, Boolean setType) [0x00000] in <filename unknown>:0
at ExitGames.Client.Photon.Protocol16.SerializeHashTable (ExitGames.Client.Photon.StreamBuffer dout, ExitGames.Client.Photon.Hashtable serObject, Boolean setType) [0x00000] in <filename unknown>:0
at ExitGames.Client.Photon.Protocol16.Serialize (ExitGames.Client.Photon.StreamBuffer dout, System.Object serObject, Boolean setType) [0x00000] in <filename unknown>:0
at ExitGames.Client.Photon.Protocol16.SerializeParameterTable (ExitGames.Client.Photon.StreamBuffer stream, System.Collections.Generic.Dictionary`2 parameters) [0x00000] in <filename unknown>:0
at ExitGames.Client.Photon.Protocol16.SerializeOperationRequest (ExitGames.Client.Photon.StreamBuffer stream, Byte operationCode, System.Collections.Generic.Dictionary`2 parameters, Boolean setType) [0x00000] in <filename unknown>:0
at ExitGames.Client.Photon.EnetPeer.SerializeOperationToMessage (Byte opCode, System.Collections.Generic.Dictionary`2 parameters, EgMessageType messageType, Boolean encrypt) [0x00000] in <filename unknown>:0
at ExitGames.Client.Photon.EnetPeer.EnqueueOperation (System.Collections.Generic.Dictionary`2 parameters, Byte opCode, Boolean sendReliable, Byte channelId, Boolean encrypt, EgMessageType messageType) [0x00000] in <filename unknown>:0
at ExitGames.Client.Photon.PeerBase.EnqueueOperation (System.Collections.Generic.Dictionary`2 parameters, Byte opCode, Boolean sendReliable, Byte channelId, Boolean encrypted) [0x00000] in <filename unknown>:0
at ExitGames.Client.Photon.PhotonPeer.OpCustom (Byte customOpCode, System.Collections.Generic.Dictionary`2 customOpParameters, Boolean sendReliable, Byte channelId, Boolean encrypt) [0x00000] in <filename unknown>:0
at LoadBalancingPeer.OpRaiseEvent (Byte eventCode, System.Object customEventContent, Boolean sendReliable, .RaiseEventOptions raiseEventOptions) [0x00134] in C:\Users\EAZYE\Documents\New Unity Project2\Assets\Photon\Photon Unity
and the second player when player goes back to the scene i get this error
PhotonView ID duplicate found: 1. New: View (0)1 on GameManager (scene) old: View (0)1 on GameManager (scene). Maybe one wasn't destroyed on scene load?! Check for 'DontDestroyOnLoad'. Destroying old entry, adding new.
any ideas please??
photonview.png
(11.2 kB)
Comment
For everyone who is interested, we have the same discussion here.