Photon player RaiseEvent sending bools

Hi there,
I’m having issues sending my bool across the network and I’m using the RaiseEvent from photon and I’m not sure I really understand it and that’s why it’s not working.
My scenario is: there are 4 players and once a player hits a button then they ready up and that’s it but I can’t seem to send the ‘playerXactivated’ bool across.

Here is my code, if someone can help me understand that would be great!:slight_smile:

#region Testing Variables
    byte eventCode = 0;
    bool reliable = true;

    #endregion

    #region Testing Methods
    void OnEnable()
    {
        PhotonNetwork.OnEventCall += this.OnEvent;
    }
    void OnDisable()
    {
        PhotonNetwork.OnEventCall -= this.OnEvent;
    }

    private void OnEvent(byte _eventCode, object content, int senderid)
    {
        if(_eventCode == 0)
        {
            PhotonPlayer sender = PhotonPlayer.Find(senderid);
            byte[] test = content as byte[];
            for (int i = 0; i < test.Length; i++)
            {
                byte unitId = test*;*

}
}
}
#endregion

#region Public Methods
public void ThiefCollectionButton()
{
PhotonNetwork.RaiseEvent(eventCode, player1Activated = true, reliable, null);
canvasObj.SetActive(false);
}
Thanks again!

Hi,

the problem is that you are sending just a boolean value but trying to cast it to an array of bytes in the OnEvent function, which obviously won’t work at all. So in order to make this work you would have to do something like bool test = (bool) content;.

However instead of using RaiseEvent in this case, I would recommend you using the Custom Player Properties. Whenever a client presses a certain button, he can use his Player Properties to let each other client know, that he is ready. This can be done by using the following code snippet for example:

ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable() { { "PlayerIsReady", true } };
PhotonNetwork.player.SetCustomProperties(properties);

Whenever a client set his Player Properties, those are automatically updated on each other client as well. The client is notified about this when the callback void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps) is called. You can see how this callbacks works here.

The MasterClient can use this callback and iterates through the player list in order to see if all clients are ready (if you want this scenario).