Question: ```
GameObject parent = GameObject.Find("Moving Object Parent");

        for (int i = 0; i < numberOfObjectsToMove; i++)
        {
            var objectToMove = Instantiate(objectToMovePrefab, parent.transform);
            objectToMove.name = "Platfrom";

            foreach (Transform g in objectToMove.GetComponentsInChildren<Transform>())
            {
                g.GetComponent<WaypointsFollower>();

                if (g != null)
                    waypointsFollowers.Add(g.GetComponent<WaypointsFollower>());
            }
        }

```

If I'm using a breakpoint on the waypointsFollowers.Add I see :

[![Adding nulls](https://i.stack.imgur.com/muA4b.jpg)](https://i.stack.imgur.com/muA4b.jpg)

Answer: 
You're comparing `g` to `null`, which won't happen unless something go very wrong. You probably want to compare `WaypointsFollower` component to null.

```
WaypointsFollower f = g.GetComponent<WaypointsFollower>();

if (f != null)
{
    waypointsFollowers.Add(f);
}

```
As was stated before that check

```
if (g != null)

```

doesn't make much sense. This will always be the case anyway since

```
 objectToMove.GetComponentsInChildren<Transform>()

```

will never return any `null` entry. You rather want to check if the `WaypointsFollower` component was found on that object.

---

There are of course multiple ways to get what you want but why not simply search for the correct component right away

```
waypointsFollowers.AddRange(objectToMove.GetComponentsInChildren<WaypointsFollower>());

```

and forget about that loop and check at all ;)

---

The better alternative to [this answer](https://stackoverflow.com/a/67629849/7111561) but without using `GetComponent` twice would be

```
foreach (Transform g in objectToMove.GetComponentsInChildren<Transform>())
{
    if (g.TryGetComponent<WaypointsFollower>(out var waypointsFollower))
    {
        waypointsFollowers.Add(waypointsFollower);
    }
}

```

but as said why even search and check all child objects if you can get those components already directly via the first solution?

---

In both cases you might want to pass in `true` as parameter to `GetComponentsInChildren` in order to also find inactive and disabled components.