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??
0
Comments
-
Help me please0
-
bump0
-
Hi @skokon,
the problem is, that you can't serialize Lists with PUN by default. You would have to use theToArray()
function on this list to convert it to an array. This however might still not work, because the type of Player is unknown to Photon and can't be serialized, too. You maybe would have the possibility to add a Custom Type for Player so that Photon can serialize this type, but I would suggest another approach to you.
Whenever a player instantiated an object, you can use the Awake function and set this object as TagObject of the related PhotonPlayer. You can do this by usingphotonView.owner.TagObject = gameObject;
.
To get a certain player's object, you can usePhotonNetwork.playerList
(an array which contains all PhotonPlayers in the room) with the index of that player. For example:PhotonNetwork.playerList[0].TagObject
.1 -
@Christian_Simon Hello, thanks now im using TagObject but how i can use it?, i mean im returning playerClass but i can't get the gameobject from tagobject...0
-
@Christian_Simon i fixed it, thank you so much!0