- Home /
UnityException: Transform Child Out of Bounds
I'm getting an error, Transform child out of bounds, that stops working after the line of code that doesn't work. "if (hand.GetChild(weaponSelection).GetComponent().weaponID == weaponID)" I tried testing for children in the hand GameObject before using the GetChild code but it still comes up with the same error. I am trying to test all of the children of the hand GameObject for the same ID as an entered ID but it whenever I try to test the code a bunch of errors keep on popping up. Please help, thank you.`if (hand.childCount > 0) { while (weaponSelection <= hand.childCount) { if (hand.GetChild(weaponSelection).GetComponent().weaponID == weaponID) { hand.GetChild(weaponSelection).gameObject.SetActive(true); } else { hand.GetChild(weaponSelection).gameObject.SetActive(false); }
weaponSelection++;
}
}`
Your answer
![](https://koobas.hobune.stream/wayback/20220612095143im_/https://answers.unity.com/themes/thub/images/avi.jpg)