# OnConstruction and BP construction script order

**URL:** <https://forums.unrealengine.com/t/onconstruction-and-bp-construction-script-order/450157>\
**Category:** C++\
**Tags:** constructors, unreal-engine, construction-script, CPP, question\
**Created:** [June 4, 2019, 10:29pm UTC](https://forums.unrealengine.com/t/onconstruction-and-bp-construction-script-order/450157 "2019-06-04T22:29:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amoffat](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@amoffat](https://forums.unrealengine.com/u/amoffat)\
**Post date:** [June 4, 2019, 10:29pm UTC](https://forums.unrealengine.com/t/onconstruction-and-bp-construction-script-order/450157/1 "2019-06-04T22:29:57Z")

</div>

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:

![278860-bp-construction.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/0/2/9028a711ebf0366c9979c88434789adcce7af3ef.png)

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

![278861-construction.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/b/a1b6e16b49343e5f9c8de9f41eb362f68c7640aa.png)

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?

---

<div class="post-metadata">

**Author:** ![BreakMaker](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/breakmaker/32/971651_2.png) [@BreakMaker](https://forums.unrealengine.com/u/BreakMaker)\
**Post date:** [December 4, 2022, 11:48am UTC](https://forums.unrealengine.com/t/onconstruction-and-bp-construction-script-order/450157/2 "2022-12-04T11:48:17Z")

</div>

I came to the same observation, and it is a pity there is no information about this.

In my situation I have a function in a BP construction script which takes in a vector as input paramter, and this vector I set from OnConstruction(). I would have expected that OnConstruction() runs earlier then the BP construction script.

However, unfortuantely the BP construction script function executes before (about 14 ms earlier) than the C++ code and the function does not work properly.

---

<div class="post-metadata">

**Author:** ![Chatouille](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chatouille/32/1194622_2.png) [@Chatouille](https://forums.unrealengine.com/u/Chatouille)\
**Post date:** [December 5, 2022, 9:56am UTC](https://forums.unrealengine.com/t/onconstruction-and-bp-construction-script-order/450157/3 "2022-12-05T09:56:52Z")

</div>

They are two dfiferent functions.

BP Construction script is declared as `UserConstructionScript` which is a BlueprintImplementableEvent so it cannot be overriden in C++.

`OnConstruction` is a separate virtual native method with no base implementation  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/7/5/175ed3ef65565c4d7be48139fa16a066e9124ab6.png)  
(so calling Super::OnConstruction is kinda useless)

`OnConstruction` is always executed after `UserConstructionScript`.

However what you can do is, declare a new “PostConstruction” blueprint overridable, and trigger it from your OnConstruction override.

```cpp
//.h
virtual void OnConstruction() override;

UFUNCTION(BlueprintImplementableEvent)
void PostConstruction();

//.cpp
void AMyActor::OnConstruction()
{
    Super::OnConstruction();

    //...

    PostConstruction();
}

```

* * *

Alternatively, maybe you can use an earlier method in the C++ construction steps, if you just need to change things before BP construction script :

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/e/c/bec01880adc7f044362657c6c248d73e36cddc8f.png)

---

<div class="post-metadata">

**Author:** ![BreakMaker](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/breakmaker/32/971651_2.png) [@BreakMaker](https://forums.unrealengine.com/u/BreakMaker)\
**Post date:** [December 19, 2022, 5:38pm UTC](https://forums.unrealengine.com/t/onconstruction-and-bp-construction-script-order/450157/4 "2022-12-19T17:38:34Z")

</div>

Found a similar response when digging some more. I got this reply on UDN from Jon Lambert from Epic Games (maybe you find it useful):

"  
AActor::UserConstructionScript is the BlueprintImplementable event that is called the “Construction Script” in the Blueprint Editor. It’s a common misconception, but the OnConstruction function is not really meant to be the native equivalent of the UserConstructionScript, a.k.a. Blueprint Construction Script. OnConstruct is called after the Blueprint’s components have been created and registered, so it shouldn’t be used to inform the UserConstructionScript, but it’s good for setting values or running some post construction setup. The reason it works in the level editor, but not in a spawned actor is because OnConstruct get’s a chance to run before subsequent reruns of the UserConstructionScript that occur while you are editing the instance. When spawning the actor, ExecuteConstruction is only run once, so the property isn’t set in time for your construction script. In your case, it sounds like you could move the logic out of OnConstruct and into a Blueprint Callable function and call that from your BP’s construction script.  
"
