Setting component active on a child object of a child object

Hello!

I’ve got this code part:

GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("Jatekos", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);

This does activate the Main Camera component if the hierarchy is like this:
-Jatekos
—Main camera

But my player hierarchy is like this:
-Jatekos
—FPSCamera
------Main Camera

What code should I use to set the Main Camera component active with my hierarchy?

myPlayerGO.transform.FindChild("FPSCamera").FindChild("Main Camera").gameObject.SetActive(true);

This should work.

1 Like

Thanks for the superfast reply! It’s working fine :slight_smile:

I’ve got some other issue:
Here is what I got:

((MonoBehaviour)myPlayerGO.GetComponent("Smooth Mouse Look")).enabled = true;

Now this code enables Smooth Mouse Look at the top of the hierarchy.
I need to change status of Smooth Mouse Look in this hierarchy:
-Jatekos
—FPSCamera —> Smooth Mouse Look COMPONENT

It should be something like this:

((MonoBehaviour)myPlayerGO.transform.FindChild ("FPS Camera").GetComponent("Smooth Mouse Look")).enabled = true;

But this is not working :frowning:

The code was right, it’s now working, only mistake was that SmoothMouseLook doesent need space between words. :slight_smile: