RaiseEvent content Error!

Options
FGk
FGk
Hi guys, I'm trying to raise an event when a player disconnects but I have a problem. Part of my code:

void Awake() { options.CachingOption = EventCaching.AddToRoomCache; options.Receivers = ReceiverGroup.All; Debug.Log("OnEvent registered."); PhotonNetwork.OnEventCall += this.OnEvent; } private void OnEvent(byte eventcode, object content, int senderid) { if (eventcode == 5) { player = (PhotonPlayer)content; Debug.Log(player); <------ NULL ........ // rest of code ...... } } void OnPhotonPlayerDisconnected(PhotonPlayer otherPlayer) { if (PhotonNetwork.isMasterClient) { PhotonNetwork.RaiseEvent(5, otherPlayer, true, options); } }
So the problem here is that player is Null inside OnEvent method. Any ideas??

Comments

  • Nobrega
    Options
    I don't know if you can send a photon player in an event. Try sending the photon player's ID instead and then getting the player from the ID when you receive the event.
  • Hi,

    sending a PhotonPlayer as parameter shouldn't be a problem, since it's already added to the CustomTypes class that is included in the PUN package.

    @FGk I don't understand what you want to achieve by 'forwarding' the disconnected PhotonPlayer to the other players, because they will receive OnPhotonPlayerDisconnected as well. Please correct me if I got something wrong, but this doesn't make any sense to me.
  • FGk
    Options
    Guys thank you for the replies!

    @Nobrega , it is possible to send a PhotonPlayer as a parameter. I am already doing that onPhotonPlayerConnected() and it works.

    @Christian_Simon you are probably right but I thought that it would be a better technique if MasterClient was the one who adds and deletes elements from my array instead of all clients doing the same simultaneously. I am new to Photon, so I don't know which one is better. What do you suggest?
    Btw, I tried doing this without RaiseEvent() and it worked. Still, the reason in unknown to me.
  • MasterClient was the one who adds and deletes elements from my array


    What kind of information do you store in this array? If it's player information, those are also stored in PhotonNetwork.playerList so you don't have to store these data, too. In general using OnPhotonPlayerConnected and OnPhotonPlayerDisconnected should be enough.

    There is at least one case where it's better, if all clients have stored and access to the same data: if the MasterClient disconnects (accidently, forced or whatever reason) and he is the only one who have stored this information, they are lost. Please think about that scenario, too.
  • FGk
    FGk
    edited August 2017
    Options
    @Christian_Simon I have to store these data because I have my own array of players who are in my Room. If MasterClient disconnects shouldn't all these data transfered on the next MasterClient automatically?
    Btw, in my case, data are stored on all clients but the one who changes them are the MasterClient.
  • If MasterClient disconnects shouldn't all these data transfered on the next MasterClient automatically?


    No, this sadly doesn't work if you have a 'custom' array with data. I would recommend you reading the Master Client and Host Migration doc page for this topic, if you didn't have already. It gives a good overview about the topic and has further recommendations about how to handle things.

    Back to your case: Besides working with OnPhotonPlayerConnected and OnPhotonPlayerDisconnected you can also try using the Player Properties and see if those are working for the things you want to achieve.
  • FGk
    Options
    Thank you very much for your help and the info @Christian_Simon.