USceneComponent::GetChildComponent index?

I’m trying to get a specific child of a scene component, and this function works fine if I give it the right index, but I can’t seem to figure out how you know what index to actually look for. How would you know what index is attributed to a child component and is there a way to reliably set it?

Alternatively I could just use GetChildrenComponents but this seemed like a nice to do it and I’m curious about the component index .

Thanks!

Hey -

If you create a blueprint of your class, you can determine the array element of a component based on it’s position in the component hierarchy. Given the screenshot below, Capsule is index 0 and StaticMesh is index 1 of a GetChildComponent call using DefaultSceneRoot as the target. SkeletalMesh does not appear in this array because it is a child of the StaticMesh instead of the scene component.

Another alternative would be to take the return value and cast it to the class of the component you’re looking for. If the cast succeeds that means the component being returned is of the type you’re looking for.

Here is the screenshot to help explain the first case:

107003-scenecomparray.png

Cheers

Good that’s what it seemed like. Any way of reorganizing children with the same parent? Say I wanted to have the capsule in index 1 instead of 0 in your example.

Thanks a lot!

If you click and drag the static mesh to the capsule it will make the static mesh a child. If you then click and drag the static mesh to the capsule again, it will unparent the static mesh below the capsule, effectively swapping their position in the GetComponents array.

Oh I see…maybe it was too simple haha

Thanks for the help!