“Solved” it, for anyone who is interested:
I added an “InitPreview” method in C++ which is called in the ConstructionScript. This is surrounded by #if WITH_EDITOR
.
// create preview component
if (ItemToSpawn)
{
AActor* Owner = GetOwner();
check(Owner);
UChildActorComponent* PreviewCmp = GetChildComponentByClass<UChildActorComponent>(this);
if (!PreviewCmp)
{
PreviewCmp = Cast<UChildActorComponent>(Owner->AddComponentByClass(UChildActorComponent::StaticClass(), true, FTransform::Identity, false));
if (PreviewCmp)
{
PreviewCmp->AttachToComponent(this, FAttachmentTransformRules::SnapToTargetIncludingScale);
PreviewCmp->bIsEditorOnly = true;
PreviewCmp->SetHiddenInGame(true);
}
}
if (PreviewCmp)
{
PreviewCmp->SetChildActorClass(ItemToSpawn);
}
}
In BeginPlay
I destroy the ChildActorComponent
. It works