[PUN2] Ownership Callback Documentation - mistakes/lack of clarity?

Options
I've just started using PUN2 for a multiplayer adventure game, which is going to involve a lot of transferring and enforcing ownership of objects. Unfortunately, it seems the documentation at https://doc-api.photonengine.com/en/pun/v2/interface_photon_1_1_pun_1_1_i_pun_ownership_callbacks.html is somewhat lacking (if I had to guess, I'd say it had been copy-pasted from PUN classic?)

A few questions that arise from looking at this page:

"This interface is used as definition of all callback methods of PUN, except OnPhotonSerializeView." -> seems to be badly-named then, I would have expected the IPunOwnershipCallbacks interface to define only those callbacks related to Ownership? (Although, it seems you don't actually need to explicitly reference this interface anyway - you can just include the desired callbacks by name in any script)

"Preferably, implement them individually" -> I'm not sure what that means? How can you implement a callback method any way other than individually? Do you mean that you should only have one script - i.e. a centralised Network Object Manager object - that implements these methods within a project? (that seemed to be the advice given in Pun v1, here: https://doc.photonengine.com/en-us/pun/v1/demos-and-tutorials/package-demos/ownership-transfer)

"MonoMehaviour" -> Typo of MonoBehaviour

"PUN will call these methods on any script that implements them", but then, further down the page "OnOwnershipRequest is Called when another player requests ownership of a PhotonView from you (the current owner). " - so is OnOwnershipRequest called on *every* object, or only on the one that contains the photonView being requested for transferral?

In the description of both OnOwnershipRequest() and OnOwnershipTransfered() it states "The parameter viewAndPlayer contains: PhotonView view = viewAndPlayer[0] as PhotonView;", but there isn't a parameter called viewAndPlayer - there are two parameters called targetView and requestingPlayer.

Any clarification on exactly the conditions, and on which clients, these two methods are called would be gratefully appreciated!


Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited April 2020
    Options
    Hi @tanoshimi,

    Thank you for choosing Photon and for your report!

    We will look into this and fix the documentation.
  • tanoshimi
    Options
    Thanks for your swift reply @JohnTube - yes, I did check (I think!) that I was looking at the correct version documentation - it has v2 in the url path, and the top of that page clearly says 2.17. It's just the page itself that seems to be out-of-date.

    I've just found this thread that describes someone experiencing similar confusion about when and where the callbacks are used - https://forum.unity.com/threads/photon-transferownership-behaving-strangely.783179/

    It seems that Pun "Classic" had/has a sample to demonstrate transferring ownership, but there isn't one for Pun2, which I found surprising, because it seems to me to be quite a fundamental use case?
    Or perhaps I'm misunderstanding something - I'd be grateful if I explain what I'm trying to do in more detail, and you could advise whether I'm following the correct approach?
    - I have between 2-4 players in the room. Each has their own photonView which is responsible for character movement etc., - synchronised using a combination of Photon Transform view and custom serialisation and this all works fine.
    - There are also a number of movable items - chests, boxes etc. which are initially present in the scene. Since these are included in the scene hierarchy, they are initially owned by the scene itself.
    - Players are able to interact with and move these items, so long as no other player is in the process of doing so. In order to do that, when a player attempts to move the item, they first call RequestOwnership() (the photonView is set to OwnershipOption.Request). If no other player is currently in the process of moving the box, the request is allowed and ownership transferred to the new player so that they can perform updates.

    So, what I'm trying to do is determine which object should be responsible for deciding whether the transfer request should go ahead or not. Is it just the currently active owner of a photonView that gets OnOwnershipRequest() called? (in which case, that method needs to be implemented on every player character script and possibly goes against the "implement them individually" advice?). Or does an OnOwnershipRequest() get fired every time any player tries to take control of any object? (which seems to contradict the description).
    The follow-on from understanding this is then whether I implement the "object is currently being moved" flag on each player script or whether it belongs in a global "object interaction manager" (which is going to get very spaghetti-like if it has to deal with all possible ownership transferrals - this is going to apply to hundreds of gameobjects).

    Many thanks for your attention.



  • tanoshimi
    Options
    For my own benefit (and for anyone else coming to this thread), here's the actual behaviour I'm finding out from emplirical testing so far:
    • If you want to receive these callbacks, your script really *does* need to implement IPunOwnershipCallbacks - simply having methods named OnOwnershipRequest and OnOwnershipTransfered in a Monobehaviour as suggested in the docs will not cause them to be called.
    • Both callbacks will be called on every script that implements them, for every ownership transfer that takes place (or is requested) - they are not only called on the scripts attached to the photonView or clients in question.
    • The correct function signatures are OnOwnershipRequest(PhotonView targetView, Player requestingPlayer) and OnOwnershipTransfered(PhotonView targetView, Player previousOwner) - not the object array viewAndPlayers[].

    It's not ideal, but at least if that's predictable I can work around it!