Transfer OwnerShip confusing

Options
Grant
Grant
I'm just not understanding the docs or example code for Transfer ownership. This is what the interfaces provide:

    public interface IPunOwnershipCallbacks
    {
        /// <summary>
        /// Called when another player requests ownership of a PhotonView from you (the current owner).
        /// </summary>
        /// <remarks>
        /// The parameter viewAndPlayer contains:
        ///
        /// PhotonView view = viewAndPlayer[0] as PhotonView;
        ///
        /// Player requestingPlayer = viewAndPlayer[1] as Player;
        /// </remarks>
        /// <param name="targetView">PhotonView for which ownership gets requested.</param>
        /// <param name="requestingPlayer">Player who requests ownership.</param>
        void OnOwnershipRequest(PhotonView targetView, Player requestingPlayer);

        /// <summary>
        /// Called when ownership of a PhotonView is transfered to another player.
        /// </summary>
        /// <remarks>
        /// The parameter viewAndPlayers contains:
        ///
        /// PhotonView view = viewAndPlayers[0] as PhotonView;
        ///
        /// Player newOwner = viewAndPlayers[1] as Player;
        ///
        /// Player oldOwner = viewAndPlayers[2] as Player;
        /// </remarks>
        /// <example>void OnOwnershipTransfered(object[] viewAndPlayers) {} //</example>
        /// <param name="targetView">PhotonView for which ownership changed.</param>
        /// <param name="previousOwner">Player who was the previous owner (or null, if none).</param>
        void OnOwnershipTransfered(PhotonView targetView, Player previousOwner);


So for OnOwnershipTransfered which is it? Does it take an object array as the docs state or the targetView and previousOwner parameters? Furthermore, it won't let me implement anything but the latter as above but previousOwner seems to return the owner doing the requesting. It also appears that both callbacks (OnOwnershipRequest and OnOwnershipTransfered) are called on both the requesting client's machine and the owner's machine. Both are called on both! Why is this? Is this intended behavior? Seems OnOwnershipRequest should only get called on the owner's node while OnOwnershipTransfered gets called on the requestor's node.

Comments

  • Grant
    Options
    Bump. Really need help on this. Thanks!
  • jeanfabre
    Options
    Hi,

    just replied on that thread: https://forum.unity.com/threads/photon-transferownership-behaving-strangely.783179/

    First of all, you need to request Ownership, please check the script OnClickRequestOwnership to check how it's done.

    then, you need to implement on your network prefab susceptible to owner ship changes that interface.

    - OnOwnershipRequest will called to the PhotonView requested for a change, it's then up to the instance to acknowledge it or not, by doing view.TransferOwnership(requestingPlayer.ID);

    - OnOwnershipTransfered, will be cakked once TransferOwnership() was called.

    So don't over think this, it's actually a simple process.

    Check out PUN classic on a fresh project, and check the demo ownership, it will have all the code for this.

    Also, make sure to read on the doc for that interface: https://doc-api.photonengine.com/en...on_1_1_pun_1_1_i_pun_ownership_callbacks.html

    Let me know if you still have troubles.

    Bye,

    Jean