GetChildrenComponents does not work!

Tell me, please, why not write GetChildrenComponents child components in an array?

SceneComponent->GetChildrenComponents(true, Components);

Hey MrPrane,

What exactly isn’t working as you expect when it comes to GetChildrenComponents?

I’ve just tested this myself and I was able to successfully get an array of child components from one of my actors using the following code:

TArray<USceneComponent*> ChildArray;

JumpPadCollision->GetChildrenComponents(true, ChildArray);

To test this, printed a message to my log and it contained the expected component:

if (ChildArray[0] != NULL)
	{
		USceneComponent* ChildComp = ChildArray[0];

		UE_LOG(LogTemp, Warning, TEXT("Component: %s"), *ChildComp->GetName());
	}

Let me know if that code works for you, and if not, please provide the code that you are using so I can take a closer look.

I did the same as you, but I have nothing.

TArray Components;
USceneComponent* SceneComponent;
SceneComponent->GetChildrenComponents(true, Components);
if (Components[0] != NULL)
{
USceneComponent* ChildComp = Components[0];
GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Green, FString::Printf(TEXT("Component: %s"), *ChildComp->GetName()));
}

All I knew after 8 hours :slight_smile: We had to use RootComponent instead SceneComponent and register in BeginPlay, not in the constructor. Huge thank you for the help))

RootComponent->GetChildrenComponents(true, Components);

I have a new problem: when you turn on the component through physics blueprnt it is no longer written to the array. Can you please tell how to fix this problem?

This is by design. Take a look at the ticket referenced below: