Get instances of a script in children

Hello there! I am trying to run a script that allows me to access all instances of a script within the children of an object. To do this, I have tried the following:

//simplified script to pinpoint the issue

private Component hitBoxes;

void Update()
//get hitboxes in object
hitBoxes = GetComponentsInChildren<AIHitbox>();
                foreach (AIHitbox hitBox in hitBoxes)
                { //call this function on each instance

Thank you in advance!

GetComponentsInChildren expects to return an array, where as you are trying to assign the result to ‘hitBoxes’, which is not an array.

Additionally, you are passing the type AIHitbox into the call to GetComponentsInChildren, but assigning it to a hitBoxes, which is a component.


private Component hitBoxes;


private AIHitbox hitBoxes;

should fix your problems