Find all Cameras descendants of a GameObject

Hi All,
I need to find all Cameras that are descendants of a GameObject. I need to find them by type not by name.
There is a “Object.FindObjectsOfType” but since it is a static method, as far as I can understand it returns all Cameras in the scene not only Cameras descendants of a specific GameObject.

Any idea?

Regards,
Gianni

Something like this should do the trick of finding all children objects, then its just a matter of getting the camera components:

GameObject.GetComponentsInChildren<Camera>();
1 Like

3837436--324016--upload_2018-10-30_14-47-6.png

That should work. Have you made a class named Camera? That’ll conflict with the built-in Camera class.

I need to find Unity objects of type Camera in the scene.
Anyway even if I define a class named Camera I use a different namespace.

As I reported previously the suggested code does not work!

3909214--333094--2018-11-20_12-14-04.jpg

Custom camera type not derived from component

Eh, yes I know, that’s why the suggested solution does not work. I reported that only to show you the error and ask for a different solution then.
So, any other idea to get All Camera as chidren (or children of children and so on recursively) of a GameObject?

You need to target the correct type. You’re apparently targeting your own “Camera” class - you probably have that class’ namespace imported and not UnityEngine.

You could:

GetComponentsInChildren<UnityEngine.Camera>();

I do not believe you, because it would work. Check your using, your using should point to UnityEngine.Camera

3909469--333130--upload_2018-11-20_13-16-24.png