OnConstruction and BP construction script order

amoffat
Tue, 04 Jun 2019 22:29:57 +0000
C++

I have a C++ pawn subclass with OnConstruction overidden:

void AMyPawn::OnConstruction(const FTransform& transform)
{
    UE_LOG(LogTemp, Warning, TEXT("OnConstruction"))
    Super::OnConstruction(transform);
}

In the Editor, I’ve created a Blueprint from AMyPawn, and created the following Construction script:

When the construction scripts run however, this is what I see in the log:

These messages seem out of order. I would expect my parent class’s OnConstruction method to behave like a C++ constructor and run before the subclassed construction script, or at least when I explicitly call Super::OnConstruction. But this doesn’t seem to be the case.

The underlying problem that led to this is that I’m creating a procedural mesh in C++ OnConstruction, but I’m setting its material in the BP subclass. I can’t do this however because my OnConstruction uses UKismetProceduralMeshLibrary::CopyProceduralMeshFromStaticMeshComponent, and that blows away any material data set by the BP construction script.

Is it incorrect to use both a BP and a C++ construction script? Is there a better way to approach this?

4 posts - 3 participants