Search Unity

Third Party PUN2 - Can't distinguish Scene from Master with TransferOwnership(0)

Discussion in 'Multiplayer' started by WeiTinYuen, Aug 26, 2021.

  1. WeiTinYuen

    WeiTinYuen

    Joined:
    Mar 27, 2019
    Posts:
    8
    I'm trying to make scene objects that can be selected by players (including the master) using
    photonView.TransferOwnership(0); 
    This works in an older project & version, which sets photonView.Owner as null (Displays 'Scene' in inspector). However in the newer project I'm working on, it sets photonView.Owner to 1 (Master). This is problematic since I want players to recognize that it belongs to the scene and not the Master who is also a player.

    I read that scene objects basically belong to the master, is there any way for me to differentiate the master's ownership from the scene's ownership?

    Pun 2.12 / Unity 2019.1.2f
    upload_2021-8-26_14-48-34.png

    Pun 2.3 / Unity 2019.4.7f
    upload_2021-8-26_14-49-14.png
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Is this PUN 2.35?
    There is always a controller and an owner for PhotonViews. If either is 0, the Master Client steps in. If the Master Client drops, the next Master will take over.
    Please check if the OwnerId is 0. Even if the OwnerId is 0, the Owner will show up as the Master Client.
     
  3. WeiTinYuen

    WeiTinYuen

    Joined:
    Mar 27, 2019
    Posts:
    8
    Pun 2.30
    Yeah that's the behaviour I'm seeing. Is there a way I can recognize the PhotonView is not in explicit control by the Master Client or any other player, by looking at Owner/Controller? It looks like the default ownership/control will always be the Master, and I will have to manually code a state for an 'unowned' object.
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Sorry, there is no direct support for "unowned" object. Potentially you can set the ownerId to 0.
    I recommend an update to latest PUN 2.35. Could be that 2.30 didn't get all updates for control / ownership yet.
     
  5. EmadKurd

    EmadKurd

    Joined:
    Oct 23, 2017
    Posts:
    4
    I am having the same issue
    Before I could become the owner of any networked scene object and give back the owner to the scene
    By doing the following

    public void OnOwnershipRequest(PhotonView targetView, Player requestingPlayer)
    {
    // carJeep is the car with photon view i wanted to control
    if (targetView != carJeep.GetComponent<PhotonView>())
    return;
    // isXomincar is a bool for checking if i entered the //car already
    if (isXomIncar == true && carJeep.GetComponent<PhotonView>().isSceneView)
    {
    carJeep.GetComponent<PhotonView>().TransferOwnership(requestingPlayer);
    }
    //isXomIncar == false is a bool for checking if i //already exit the car
    else if (isXomIncar == false && carJeep.GetComponent<PhotonView>().IsMine)
    {
    carJeep.GetComponent<PhotonView>().TransferOwnership(0);
    }
    }

    by using that I could become the owner of the scene object and then dis own and give it back to the scene but now my pun version is 2.40 it does not work.
    can anyone please send me some code or anything that helps me I appreciate that thank you
     
    Last edited: Jan 2, 2022
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Even if you gave the object "back to the scene", it was effectively controlled by the Master Client.
    However, it wasn't shown as such in all cases.
    In which way is the update affecting you??
     
  7. EmadKurd

    EmadKurd

    Joined:
    Oct 23, 2017
    Posts:
    4
    Thanks for reply
    When the scene load normally each player chooses a car automatically depending on their actor number and they own that car via on ownership request so Anyone can drive their car while they are in that car and own it
    And disown the car while exit the car

    I do not have any problem in photon v 2.27 but in above version from v2.28 till v2.40 Not any player can take control of the car
    When I am the maser and drive the car it drives other player car as well but does not update the position of the car in other player screen
    When I use any version under 2.27 I do not have any problem
    But using the higher version is problem
    So I might do not now how to use the transferownership in higher version
    If so
    Why there is not any problem in lower version?
     
  8. EmadKurd

    EmadKurd

    Joined:
    Oct 23, 2017
    Posts:
    4
    Hi
    when I use photon v2.27 and lower using the below code I do not have any issue, it does do what exactly I want but in photon V2.28 and higher those code is not working
    even I changes IsScenView to IsRoomView

    if Explained in the comment line by line
    please check it and you might get what I mean
    these code is perfect for transferring ownership in v2.27 and lower but problem with 2.28 and higher
    if you can guide me how to use ownership correctly in v2.40
    I have read all docs and already tried everything but could not sort it out



    I have a function when I enter a car or exit a car it will call this


    carJeep.GetComponent<PhotonView>().RequestOwnership();

    // carJeep is the current car if I am in or out

    //and then this will happen

    public void OnOwnershipRequest(PhotonView targetView, Player requestingPlayer)

    {

    if (targetView != carJeep.GetComponent<PhotonView>())

    return;

    //this will check if the game already not started and if the photonVeiw IsMine is true

    // if so this will happen

    if (myPhotonView.IsMine && GameStarted == false)

    {

    // I will become the current car owner

    carJeep.GetComponent<PhotonView>().TransferOwnership(requestingPlayer);


    //I have 6 different cars in this for loop I will check if any of the car I owned already except for the current one

    //if I own any of them it will give back the owner ship to the scene


    for (int i = 0; i < _Jeeps.Length; i++)

    {

    if (_Jeeps.GetComponent<PhotonView>().IsMine && carJeep != _Jeeps)

    {

    _Jeeps.GetComponent<PhotonView>().TransferOwnership(0);

    }

    if (_Hummers.GetComponent<PhotonView>().IsMine && carJeep != _Hummers)

    {

    _Hummers.GetComponent<PhotonView>().TransferOwnership(0);

    }

    if (_Qamaras.GetComponent<PhotonView>().IsMine && carJeep != _Qamaras)

    {

    _Qamaras.GetComponent<PhotonView>().TransferOwnership(0);

    }

    if (_Faras.GetComponent<PhotonView>().IsMine && carJeep != _Faras)

    {

    _Faras.GetComponent<PhotonView>().TransferOwnership(0);

    }

    if (_Landcrusers.GetComponent<PhotonView>().IsMine && carJeep != _Landcrusers)

    {

    _Landcrusers.GetComponent<PhotonView>().TransferOwnership(0);

    }

    if (_Barzs.GetComponent<PhotonView>().IsMine && carJeep != _Barzs)

    {

    _Barzs.GetComponent<PhotonView>().TransferOwnership(0);

    }

    }

    }

    // if the game started and if IsMine is true

    else if (myPhotonView.IsMine && GameStarted)

    {

    //if I am in the car and the current car is owned by scene not any one, and then I become the owner of that car

    if (isXomIncar == true && carJeep.GetComponent<PhotonView>().IsSceneView)

    {

    carJeep.GetComponent<PhotonView>().TransferOwnership(requestingPlayer);

    warninMsgWhoownerisParent.SetActive(true);

    messageForwhoisOwner.text = "Car owner now Belongs to: " + carJeep.GetComponent<PhotonView>().Owner.NickName;


    }

    //If I am not in the car so it means exit the car and the car I exit ismine,

    else if (isXomIncar == false && carJeep.GetComponent<PhotonView>().IsMine)

    {

    //It ill give back the car owner to the scene

    carJeep.GetComponent<PhotonView>().TransferOwnership(0);

    warninMsgWhoownerisParent.SetActive(true);

    messageForwhoisOwner.text = "Car owner now Belongs to the Scene";

    }

    else { return; }

    }

    }
     
    Last edited: Jan 4, 2022