Add custom Actor Component to actors dynamicly

I try to mac a static function looking far all actors with a meshcomponent and to add a custom actor component to them thats what i have that dosent work:

UWorld* World = WorldContextObject->GetWorld();
	TArray<AActor*> ActorsWithMesh;
	TArray<AActor*> AllActors;
	UGameplayStatics::GetAllActorsOfClass(World, AActor::StaticClass(), AllActors);

	for (int32 i = 0; i < AllActors.Num(); i++)
	{
		TArray<UStaticMeshComponent*> TempComponents;
		if (AllActors[i])
		{
			AllActors[i]->GetComponents<UStaticMeshComponent>(TempComponents);
			if (TempComponents.Num() > 0)
			{
				ActorsWithMesh.Add(AllActors[i]);
			}
		}
	}

	for (int32 i = 0; i < ActorsWithMesh.Num(); i++)
	{
		UWorldObject* WorldObjectComponent = ActorsWithMesh[i]->CreateAbstractDefaultSubobject<UWorldObject>("WorldObject");
		ActorsWithMesh[i]->AddOwnedComponent(WorldObjectComponent);
	}

How should i do this?

Thanks in advance

kind regards

I got it working with

UWorldObject* WorldObjectComponent = NewObject<UWorldObject>(ActorsWithMesh[i],"WorldObject");
WorldObjectComponent->RegisterComponent();