IPunCallbacks doesn't work every time

Options
Hi, I'm using IPunCallbacks to detect sertain events. For now it has been working nicely, but when I made new scipt that should just log all event, it doesn't work.

So now I have couple of monobehaviour scipts that implements IPunCallbacks and most of them seems to work and still the newest one doesn't.

The newest script is very simple: http://pastebin.com/7HhYnn3T

And I have added it to one gameobject but still I don't get any Debug.Logs through.

-tkok

Comments

  • tkok
    Options
    Okay, this is interesting...

    I started to check why it worked on other scripts. Well it didn't. In other script that worked there was implemtation as:

    void IPunCallbacks.OnJoinedRoom()
    {
    menu.OnJoinedRoom();
    }

    But it didn't actually get called ever but instead menu's OnJoinedRoom function got called because the name was by chance exactly right. Then I started to check my debugger script and removed the explicite interface stuff: "void IPunCallbacks.OnConnectedToMaster()"->"public void OnConnectedToMaster()"

    And it started to work.

    Next I even removed IPunCallback implementations from class signature and it still worked.

    So I think only question left is Why on earth there is this interface if it's not really used anywhere? It's missleading, unnecessary and conflicts how interfaces should work thus leads to this kind of errors. :neutral:
  • Tobias
    Options
    We weren't aware that the explicit implementation of the interface methods does not work.
    I'm sorry you ran into this problem - it's surprising.

    The interface is there to have one "traditional" definition of all callbacks. You could implement this and any modern IDE will implement the methods for you in one go, ready to be filled with life.

    On the other hand, interfaces are often tedious. You have to implement all of those methods. So we don't make it mandatory to use the interface and instead go with Unity's approach of "event methods", along the lines of Awake() and Update().

    Unlike Unity, we can't implement our callback methods directly into the MonoBehaviour, so initially, PUN's callbacks were near-invisible and hard to document.
    We now have a PunBehaviour, which gives the callbacks a place to be and room for documentation. It's optional to use this.

    In the background, we use Unity's SendMessage. It calls methods by name and (now obvious) doesn't call fully qualified methods from Interfaces.
    The lowest level in PUN for callbacks, is their definition as enum PhotonNetworkingMessage.


    We recommend to either implement PunBehaviour or to just check it for existing callbacks and implement them one by one in a MonoBehaviour (or extending class).

  • tkok
    Options
    Thank you for clearing that up. The first issue with punBehaviour was that I had lots of inherited classes that don't inherit straight from the monobehavior but from other classes that inherits from MonoBehaviour. So I couldn't just replace it MonoBehaviour with PunBehaviour .

    I think your approach is the best that can be but your documentation of IPunCall should be improved.