Can't find PN instantiated gameobject on clients

Options
Hi,
if (PhotonNetwork.isMasterClient)//If the player is master, needs to spawn the gameController Object in the room
        {
            gameControl = PhotonNetwork.Instantiate("gameControl", Vector3.zero, Quaternion.identity, 0);
            gameControlScript = gameControl.GetComponent<gameControl>();
        }
        else
        {
            gameControl = GameObject.FindGameObjectWithTag("GameController");
            gameControlScript = gameControl.GetComponent<gameControl>();
        }

I am trying to create a list of the players' transforms so that I can call RPCs on each player.

The way I have it setup, the masterClient creates a gameControl object which is supposed to keep track of and set the gamestates for the players via RPCs.
The masterclient creates the gameobject and works fine, but then when a second client comes along and the else code is executed, I get a null reference exception trying to assign gameControl...like it doesn't exist for that client, even though it has a photonView...

Any help/comments appreciated.

Thanks.

Comments

  • Ive also tried using something like :

    Transform gameControl1 = PhotonView.Find(1001).transform

    since I know that the gameControl prefab is always the first photonView that gets instantiated it's always ID 1001 (or 1 if instantiateSceneObject)..

    but still null..
  • CoreWorkNode
    edited November 2014
    Options
    Do you want the clients to call RPC(s) on the prefab that the MasterClient Instantiated.

    Just trying to understand more, what you're trying to do.
  • Tobias
    Options
    You could add a script to the prefabs you instantiate and let them register themselves in Awake() or something.
    You can also find all PhotonViews and go through each to identify the ones you are looking for. The player who owns the PV is also available this way.