Why is my object's constructor called so many times?
I have an actor that has a custom USceneComponent I made attached to it. placing a breakpoint in the constructor, I am seeing that the constructor is called many times.
I have read that UE4 does construction in a obscure way that causes it to construct multiple times, however, I am seeing a LOT of construction, and at times I wouldn't expect it to occur.
Launch of the editor, constructor 5, destructor 1
Launching BP editor for my actor, constructor 1, destructor 0
Switching to the viewport, constructor 1, destructor 0
Closing the BP editor for my actor, constructor 0, destructor 0
Moving my actor in the level: constructor 1, destructor 0
Moving my scene component in the editor : constructor 1, destructor 0 (per frame?)
Additionally, I have a UProperty UStaticMeshComponent* that appears to be always null, each time the constructor is reached. The property has been set in the actor.
Is this normal behavior? Why? Why is the constructor called so many more times than the destructor?
Because constructors are useful in the editor, not only in-game, Unreal Engine tries to make sure your object is always updated according to its constructor.
Lets imagine an actor that has a vector with 3d widget, and a wall is stretched from the origin of your actor to that 3d widget. Now, lets assume you move this actor around in your world. Because construction is dependent on the location, unreal has to re-construct the object when you move.
So as far as i know, yes, it is normal behaviour. (But im not sure). It has been like this since at least 4.10.
answered May 30 '18 at 11:21 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here