I have created a float BlueprintImplemetable pure function in C++, and have overridden it in Blueprints to retrieve my specific value.
that function works great in every place, except for C++ constructor; in which is just retrieving null, as if it were not overridden at all.
It works in BeginPlay(), but i would like to know why is it happening in the constructor? is it a bug or feature?
I would like to mention that there are no compilation/runtime errors/warning connected to it.
Constructor is the first code when object is created, at that point object is not fully initiated and link up to reflection system, because of that calling that function in constructor won’t forward the call to blueprint. Not to mention constructor is also called when default class object (CDO) is created and engine it self is not fully initiated so doing any code aside of setting defaults and declaring components is risk of crash on engine start up.
UObjects provides events which allows to inject code in to various initiation stages, most ealiest one you can use is
Which is called when varable values are set to defaults from blueprints, in Actors you can also use this:
Which is called when components are initiated, it called right before BeginPlay only diffrence is it is also called in Editor when you place object on level as well as all previews, rermber that actor not only have gameplay code but also code how actor should behave in editor and previews
thank you very much for your detailed answer!