photonView.IsSceneView returns true after ownership has been transferred to player

Options
Hello,

I am using the following code to transfer the ownership of a photonview to a player when he connects.
public class PlayerConnection : MonoBehaviourPunCallbacks
{
    public static bool OwnsPhotonView = false;

    private void Start()
    {        
        if (!OwnsPhotonView && this.photonView.IsSceneView)
        {
            photonView.TransferOwnership(PhotonNetwork.LocalPlayer);
            OwnsPhotonView = true;
        }
    }
}

When the master client starts the room, he naturally takes ownership of the photonView. The problem is that when another client joins the room, the value of IsSceneView is true, and they then take back the ownership for themselves.

How can I stop that and make sure it's "first come first served"?

Comments

  • Divone
    Divone
    edited February 2020
    Options
    (I am using a static `OwnsPhotonView` variable, because there are two separate objects on the scene that have this code, and I want to make sure each player only controls one.

    Furthermore, the objects are manually placed on the scene and set as "Takeover".
  • sci_prog
    Options
    Why don't you just check if you are the master client and if true take the ownership?