Photon Question: OnPhotonEvent Subscription is overriding OnConnectedToMaster?

Hello,
I am currently learning PUN for the first time and I would really appreciate your help with this. I previously setup a perfectly working subscription to OnConnectedToMaster() by simply defining an override to the method within a class that derived from MonoBehaviourPunCallbacks.

The documentation later led me to implement a photon event subscription by means of
PhotonNetwork.NetworkingClient.EventReceived += OnPhotonEvent;

However to my dismay, this new subscription prevented my previously working OnConnectedToMaster() override from being called once my client connects. Said plainly: adding the additional subscription prevented my first one from working. How could this be? Additionally the new subscription's eventData does not seem to have any information that would indicate the equivalent of OnConnectedToMaster.

I have created a simple demonstration here in case that is helpful: https://youtu.be/BRAy_IT3H6w

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @MrVentures,

    Thank you for choosing Photon!
    if you extend MonoBehaviourPunCallbacks make sure to call the base class methods if you override OnEnable() and OnDisable()

    in OnEnable
    either call base.OnEnable or call PhotonNetwork.AddCallbackTarget(this);
    in OnDisable
    either call base.OnDisable or call PhotonNetwork.RemoveCallbackTarget(this);
  • Thank you so much! Can you please edit this tutorial: https://doc.photonengine.com/en-us/pun/v2/gameplay/rpcsandraiseevent that tutorial does not include the base calls and so I am sure others will be misled by it.
  • JohnTube
    JohnTube ✭✭✭✭✭
    The snippets on that page do not extend MonoBehaviourPunCallbacks only Unity's MonoBehaviour.
    The note about implementing/overriding OnEnable and OnDisable when extending MonoBehaviouPunCallbacks is present here and here.
  • That's a good point I was just thinking it may be a prudent reminder since I made a mistake there and others will likely do so as-well.