equivalent of construction script in c++

I have a blueprint that modifies the position of a scene root on construction. How can I do something similar in c++? I can’t put it in the constructor, because the variables are all set to their default values there. If I put it in BeginPlay, it works nicely, but only when I’m actually simulating / playing, not in the editor itself.

EDIT: solved it… you just need to use


virtual void OnConstruction(const FTransform& Transform) OVERRIDE;

14 Likes

I had this issue myself when making custom components, and found “OnComponentCreated” to work. What is your extending class where you use OnConstruction?

OnComponentCreated is called on an ActorComponent when it is first added to an Actor. OnConstruction is run on the Actor whenever it is spawned, a property changes or the Actor is moved, just like the ConstructionScript function in Blueprint-land.

11 Likes

Ah thanks - I figured that might be the case: One for Actors and the other is for ActorComps. OnConstruction would be very useful if is run every time a property is changed and I assume its in the ActorComponets since they extend actor iirc.

(by the way technically moving is changing property - the actors location vecter :stuck_out_tongue: )

pretty sure one should override UserConstructionScript():

image