Raise event - event not firing

Options
I am probably missing something simple - My understanding with Raise Event is that the object raising the event and the one receiving it do not need to have a PhotonView component?

I am not 100% that this is correct... Here is how I am trying to set this up. Any help is appreciated.


This is the code I have on my receiving object:

 void OnEnable()
    {
        PhotonNetwork.OnEventCall += this.OnEvent;
       
    }
void OnDisable()
    {
        PhotonNetwork.OnEventCall -= this.OnEvent;
    }
    // handle custom events:
void OnEvent(byte eventcode, object content, int senderid)
    {
        Debug.Log("event"); // never fires
    }


And the sending object:

// raise event
  
 byte evCode = 0;    
 float tempVar = 1.0f;

 float[] content = new float[] { tempVar };    

 bool reliable = true;   
 PhotonNetwork.RaiseEvent(evCode, content, reliable, null);

Comments

  • Hi @Hipshot,

    I am probably missing something simple - My understanding with Raise Event is that the object raising the event and the one receiving it do not need to have a PhotonView component?


    That's right: RaiseEvent is independent from a PhotonView component.

    To the source code you provided: the fourth parameter of the RaiseEvent call is a RaiseEventOptions object. When using null, the default options are applied internally, which set the Receivers to Others. This means, that the custom event only gets forwarded to the other clients in the room. If you want the sending client to receive this custom event as well, you would have to use non-default RaiseEventOptions. The easiest way to do this in your case is, to replace the null parameter with the following code: new RaiseEventOptions { Receivers = ReceiverGroup.All }.
  • Hipshot
    Options
    This solution worked great. TY!