Why GetComponentInChildren is not working ?

Hello,

I have a script named CloseTutorialTower located on Quit child.

OtherParents

=> Tutorial

=>=>InGameTutorial

=>=>=>RPGDialog

=>=>=>=>Quit

I use the following code to access the script :

GameObject rpgDialog = GameObject.Find("Tutorial");
			Debug.Log(rpgDialog);
			CloseTutorialTower zaScripts = rpgDialog.GetComponentInChildren<CloseTutorialTower>();
			zaScripts.OnClick();

But, even though it find the object Tutorial, it does no find the script on the childrent of Tutorial.

What am I doing wrong ?

Thanks

Maybe that script is disabled? You have to pass true to GetComponentInChildren if you want to get disabled components.

GameObject rpgDialog = GameObject.Find(“Tutorial”);
Debug.Log(rpgDialog);
CloseTutorialTower zaScripts = rpgDialog.GetComponentInChildren();
if(zaScripts)
zaScripts.OnClick();

//good luck

Since GetComponent() works on inactive objects, you can also get the transform’s child first and then use GetComponent()

yourGameObject.transform.GetChild(0).GetComponent<TextMesh>().text = "Your Text";