Download

Constructors in UE

I am an experienced C++ developer, however, I am fairly new to the Unreal Engine API; I have a question concerning object construction.

With object attributes, I may choose specifications in the UPROPERTY macro such as ‘ReadWrite’ which allows level designers to modify the default values. My questions is exactly when during object construction these values are set and when to set my default values for the object attributes.
My best guess would be to set default values in the default C++ constructor (the one that does not take any arguments, just to be precise)? As I understand the default constructor is called and subsequently the constuctor that accepts a FObjectInitialiser (see specifications: FObjectInitializer | Unreal Engine Documentation). How are the values set in the editor passed and set during object creation?

Thank you in advance

Hello!

Do you mean when these flags are set? If that is what you mean, they aren’t really set at runtime if I understand the system correctly, but rather, are harvested by the unreal header tool at compile time and then just reside as meta data when you are in the editor for the BP system to use.

It seems to me like the most common place to initialize UPROPERTY variables if you intend them to be configurable from the editor later on, is in the UCLASS constructor (which accepts FObjectInitializer). This constructor is run on editor startup and every time the game is run. The values you set in code are then treated as default values for BP; that is, any changes in BP you make will always take precedence. If you leave the BP to it’s default however, you can update values by changing your ctor code and recompiling. You can easily test this by simply setting some defaults in the ctor and then starting a PIE session.

Best regards,
Temaran