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];