Passing arguments to constructors in UE4?

AndreiPambuccian
Thu, 08 Jan 2015 15:49:38 +0000
C++

As I understand it, UE4 constructors in 4.6.1 contain a single argument, passed by address, of type FObjectInitializer. This argument may not be used to store a custom-made argument list for initializing the object that is being created. Furthermore, the three functions that are normally used to create UE4 objects, namely NewObject, NewNamedObject and ConstructObject, do not provide a means of passing arguments to the object being created. This makes it impossible, apparently, to thoroughly initialize a given object within the object’s constructor itself. One way to initialize the object would be to write an initialization method that was called after ConstructObject() returned the object, but this sort of initialization would introduce numerous inconveniences of its own, as you would need to include checks in other methods just to see if it had been called yet.

It seems as though there is no way to elegantly initialize objects in UE4. Am I missing something, though? Is there in fact a way to pass your own arguments to constructors, or at least pass initialization functions and argument lists to some function like ConstructObject?

10 posts - 1 participant