Instantiate then access component(s)

Hey guy’s I’m using Photon to instantiate my player.
(IT WORKS)

But anyone who uses photon knows that the camera and movement controls need to be disabled first then re-enabled.

Well, the way my player is set up, none of the things are directly childed to the Main parent.

The way my player is set up is like this.

Player
      FirstPersonControls
                  player
                    Capsule
                    Main Camera
           RightTouchPad
           LeftTouchPad

What I need to do is enable the Joysticks for both touch pads.
(both scripts on each one are named Joystick)

And re-enable the Main Camera

from this code below.

// we're in a room. spawn a character for the local player. it gets synced by using PhotonNetwork.Instantiate
		GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0);

Well when I try to FIND the camera with this code below

myPlayerGO.transform.Find ("Player/FirstPersonControls/player/Main Camera").gameObject.SetActive (true);

I get this error —
NullReferenceException: Object reference not set to an instance of an object
IngameNetManager.Awake () (at Assets/_Imported/_Scripts/_Network/IngameNetManager.cs:21)

I’ve tried it with FindChild as well, same outcome.

And for the Joysticks, I don’t understand how to access the “Joystick” scripts from them.
and re-enable them.

If it was all done from one object, then it was be easier to do this, but I’ve never delt with doing things with child objects.

Can you please help me?

.Find does not find diabled gameobjects/transforms. You need to make a reference before disabling it. Or you can save the reference as part of the prefab in the editor.

Not tested with photon just did a quick test in editor.

//Assign the gamera transform in the editor, and save it as part of prefab
using UnityEngine;
using System.Collections;

public class photonttest : MonoBehaviour {
    public Transform cameraTransform;
	// Use this for initialization
	void Start () {
        cameraTransform.gameObject.SetActive(true);	
	}
	

}

Hey I got it working, I’m putting it in Answer so anyone looking can understand and know this is the answer.

By the way Linus (You’re ways are correct) for Single player stuff.

But with Photon this is how I had to do it…
(Just a tad bit different) than you were pointing out.

	// THIS SCRIPT DEALS WITH NETWORKING PLAYER
	// ALSO ENABLED LOCALIZED THINGS SUCH AS CAMERA, Joysticks, etc.


	// VARIABLES FOR CAMERA AND THE JOYSTICKS
	public Transform myCam;
	public Transform LeftJoy;
	public Transform RightJoy;

	// Use this for initialization
	void Start () {
	// IF THE PLAYER IS MINE, ENABLED THESE OBJECTS.
		if (photonView.isMine) {
			myCam.transform.gameObject.SetActive(true);
			LeftJoy.transform.gameObject.SetActive(true);
			RightJoy.transform.gameObject.SetActive(true);

			} 
	}