Crash when duplicating actor

I’m getting a crash when I duplicate a custom actor.

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000000

I have a custom USceneComponent (UFlareFXBuilderComponent) which spawns UStaticMeshComponent derived child components (UFlareFXElementComponent) on request from the owning actor’s construction script. The owning actor checks a user-defined TArray, and requests creation of these UFlareFXElementComponent children based on user values. It works fine until I attempt to ALT-Drag / Copy-Paste a duplicate.

Rider gives me an error:

Error        None                      BEGIN OBJECT: No base template named FlareFXElementComponent_1 found in parent class SceneComponent:             Begin Object Name="FlareFXElementComponent_1 "

If I remove the FXBuilderComponent or comment out the code that requests creation of the components, duplicating the actor works fine.

Here is the code in the custom USceneComponent that spawns the children:

void UFlareFXBuilderComponent::RegisterElements(uint32 Count, TArray<UFlareFXElementComponent*>& OutFlareCards)
{
	TArray<UFlareFXElementComponent*> NewElements;
	for (uint32 Index = 0; Index < Count; Index++)
	{
		if (UFlareFXElementComponent* Element = NewObject<UFlareFXElementComponent>(this))
		{
			NewElements.Add(Element);
			Element->CreationMethod = EComponentCreationMethod::UserConstructionScript;
			Element->AttachToComponent(this, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
			Element->RegisterComponent();
		}
	}

	for (UFlareFXElementComponent* Element : NewElements)
	{
		OutFlareCards.Add(Element);
	}
}

And here is the code on the actor that calls this function:

TArray<UFlareFXElementComponent*> FlareCards;
FlareFX.Component->RegisterElements(FlareFX.Elements.Num(), FlareCards);

if (FlareCards.Num() != FlareFX.Elements.Num())
{
	UE_LOG(LogTemp, Warning, TEXT("%s"), *FString("Count doesn't match."));
	return;
}
			
for (int32 Index = 0; Index < FlareCards.Num(); Index++)
	FlareFX.Elements[Index].Component = FlareCards[Index];

If I move construction of the UStaticMeshComponents to the actor and attach the components to the actor’s rootcomponent, duplication works.

But the duplicate actor appears at the origin (even with ALT+Drag) and its component list in the detail panel is messed up (only shows one of the newly added components as the new root, none of the original components are shown).

I guess the question is: Is spawning components in the construction script something that is supported, and what is the correct way to do this so that duplicating the actor doesn’t produce weirdness?

I just tried creating a brand new actor using the exact same construction code and it works fine.

I’ve got no idea why.

I’ll go digging.

It was this. Not sure why this is even here, or why I put the check before the Super call. I was noodling with intercepting values to make sure they were correct, and didn’t clean up the leftovers. But with this gone, duplication works fine:

void AMyActor::PreEditChange(FProperty* PropertyAboutToChange)
{
	if (!PropertyAboutToChange)
		return;

	Super::PreEditChange(PropertyAboutToChange);
}