Nested foreach not executing inner loop

I have the following code in one of my components. The outer foreach loop works just fine (the “zone_transform” debug message prints just as expected); however, the inner foreach loop doesn’t do anything. Ever…

What is wrong with my code? Any help would be greatly appreciated.

  private IEnumerator DealOutTheCardsCoroutine() {
    Debug.Log("Handing cards out to each player stack.");

    int which_card=0;;
    foreach (Transform zone_transform in _targetPoints) {
      Debug.LogFormat("Zone Transform: {0}", zone_transform);

      foreach(Transform child_transform in zone_transform) {
        Debug.Log("Child Transform: {0}", child_transform);

        CardFlipper card = _dealtCards[which_card++];

        StartCoroutine(MoveCardToPointCoroutine(card, child_transform.position));
        yield return new WaitForSeconds(_dealCardDelay);

        child_transform.SetParent(_canvasTransform, false);
        child_transform.gameObject.SetActive(false);
      }
    }

    Debug.Log("Done dealing out all of the cards.");
    yield break;
  }

zone_transform is not an array, so it cannot be used like one in a foreach loop. Instead, try a for loop:

for (int i = 0; i < zone_transform.childCount; i++) {

and at the beginning of each iteration, set

Transform child_transform = zone_transform.GetChild(i)

I haven’t tested this but it should work. Hope this helps!

I’m not sure why it took a good night sleep to realize that there may not be any children in the zone_transform objects; but it did. Confirmed after adding a child count display to the end of the debug log message.

Which was unexpected since the game board it all stems from is a prefab. So somewhere, in one of my other components, I’m deleting them or otherwise effectively doing so anyway.

I guess I’ll look for that later this afternoon when I get home from work…

Thanks @pizza14 for your suggestion but that was the approach I had taken originally. Then I found out that I could iterate through children with a foreach loop and changed it.