"NullReferenceException: Object reference not set to an instance of an object " only for one component

I can’t figure this out at all.
Here’s the object Hierarchy:

The script is being executed from “_Scripts” and it’s working fine for ONE of the children of FPSPlayerMP10. [note myPlayerGO is the FPSPlayerMP11]

            GameObject child1 = myPlayerGO.transform.FindChild ("Player").gameObject;
		((MonoBehaviour)child1.GetComponent ("FirstPersonControl")).enabled = true;
		//Debug.Log ("Child1 Name: " + child1.name);
		GameObject child2 = myPlayerGO.transform.FindChild ("RightTouchPad").gameObject;
		Debug.Log ("Child 2 Name: " + child2.name);
		((MonoBehaviour)child2.GetComponent ("Joystick")).enabled = true;

So, the child called “Player” has a scrip called “FirstPersonControl” and when the game starts it detects the child and enables the script.
However, this does not work for the 2nd child which is called “RightTouchPad”(gameobject that has a script called “Joystick”) ,It does detect it and I get the Debug.Log in the console but for some reason it can’t find the “Joystick” Script and enable it [http://i.imgur.com/uvcF5Zz.png].
It gives me “NullReferenceException: Object reference not set to an instance of an object” , and it stops the script from going forward.

It works like charm for the “Player” Child why doesn’t it work for the second one?

Thank’s for reading and in anticipation for helping :wink:

Try getting the component with GetComponent< Joystick >().

Also try to check if the component is found.

Joystick joystick = child2.GetComponent<Joystick>();
Debug.Log("Joystick is: " + joystick );

Also why are you casting joystick as MonoBehaviour? Cast it as Joystick and enable it that way.

Thank’s for trying to help me but I found a work-around that seems to be working fine.Instead of trying to enable the disabled script on RightTouchPad and LeftTouchPad, I’ve enabled the script and disabled the RightTouchPad and LeftTouchPad game objects.

GameObject child2 = myPlayerGO.transform.FindChild ("RightTouchPad").gameObject;
		GameObject child3 = myPlayerGO.transform.FindChild ("LeftTouchPad").gameObject;
		child2.SetActive (true);
		child3.SetActive (true);