null checking -- missed the empty object

public static List<T> FindComponentsIn<T>(Transform inT, bool activeOnly = true, bool recursively = true) where T : class
    {
        List<T> res = new List<T>();
        Transform ch;
        T c;
        for (int i = 0; i < inT.childCount; i++)
        {
            ch = inT.GetChild(i);
            if (activeOnly && !ch.gameObject.activeSelf)
                continue;
           
            c = ch.GetComponent<T>();
            if (c != null)
                res.Add(c);
           
            if (recursively)
                res.AddRange( FindComponentsIn<T>(ch, activeOnly) );
        }
        return res;
    }

… this null - is some kind of some special like world ether?
and if it somehow helping for understand, then the transferred T is a Collider

I think your collider is not null. It’s just attached to a GameObject whose name is the string “null”. Here’s what my debugger looks like with an actual null component:

6272019--692655--upload_2020-9-2_17-37-6.png

And here’s what it looks like when I have a GameObject named “null”:
6272019--692658--upload_2020-9-2_17-39-22.png

Notice the quotes, the object type, and the dropdown arrow?

2 Likes

Yes, that’s right, it’s empty in quotes!

But I didn’t create an object named: null. Here is the hierarchy of objects, and here is this object that skips the check, and there are no components on it.

Okay, this looks like the result of the internal work of the engine, where it is necessary to understand this null object as a result of a failure in the engine or outside …

I just adding:

 if ( c != null && c.ToString() != "null")

Thanks for the tip, the question is closed)

6272112--692667--upload_2020-9-3_1-7-24.jpg

1 Like

Yeah my explanation doesn’t seem to completely add up because there is a Transform variable in your code ch which obviously is attached to the same object as the collider, and it’s properly showing the name of the GameObject as “Legs”. So something else weird is going on!

1 Like