transform.childCount == 0, but a child shows up in the hierarchy. How is this possible?

I got an error when trying to call transform.GetChild(0). As I debugged the problem, I found out that transform.childCount was 0, so the call was out of bounds. However, I paused the game as soon as I detected that childCount was zero, and under the hierarchy it showed that the object did have a child, as shown below:54579-hierarchy-bug.png

Is there any way this can happen?

In case it helps, this is the C# code snippet I used to debug the program:

if (transform.childCount == 0)
	UnityEditor.EditorApplication.isPaused = true;

I used the instance ID to verify that the transform of the GameObject highlighted in the hierarchy was the one with childCount == 0.

This makes no sense… please help!

by their name it’s say they’re runtime instantiations so they didn’t come in at the same time, right? possible you’re asking for child count before it exists?

I finally figured it out. I was instantiating the WaitBlock, assuming it would create its children in its Start method immediately after. However, I called GetChild before Start was called. What is still confusing is that even though I paused the game immediately, Start was still called afterward. Anyway, it’s working now. Thanks for everyone’s suggestions!