OnConstruction vs Blueprint Construction Script

I tried moving some Blueprints to C++ and found them suddenly behaving differently.

I later realised that while the Blueprint Construction Script is updating every time the Actor gets moved within the editor, the OnConstruction method of the AActor class only fires upon construction or parameter change.

So is there an easy way to recreate the Blueprint behaviour in C++? Or maybe I’m just doing something wrong? Ideas would be appreciated.

If the moved actor’s class is a blueprint generated class then it will re-run the construction scripts including OnConstruction of its native parent class and all subsequent Blueprint Construction Scripts in the hierarchy. But if the actor’s class is a native class, it will not do that (for a good reason), it will only call PostEditMove.

So if you want to do something in c++ when the actor is moved in the editor, then just override PostEditMove.

PostEditMove is the one who re-run the construction scripts if the actor class is in a blueprint, so your c++ code will work as expected for both native and blueprinted actor class.

My last solution was to promote the C++ class to a Blueprint, which seems to work as well, but PostEditMove is exactly what i originally had in mind. Thank you for pointing me there. =)

Hi, while this forum post was long answered, here an addition as some people may find it useful.

OnConstruct is called after the Blueprint’s components have been created and registered, so it shouldn’t be used to inform the UserConstructionScript.

Since there is a general misunderstanding that OnConstruct is the C++ equivalent of the BP construction script, here a response I got from Jon Lambert from Epic Games in quote:

"
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.
"