How to setup your constructor?

Hello Everybody,

My question stems from an answer I received in this post. Essentially, I had to change my constructor to use const FObjectInitializer& ObjectInitializer as a parameter. So this has led me to ask the question of, “How do you know how to setup your constructor.” For instance when should you use a regular constructor that doesn’t take in any parameters like the ones that are generated for you when you create an AActor class and when should you use constructors with parameters like those that I mentioned above?

I am still very new to Unreal Real C++ programming so any help is very much appreciated,

Farshooter

You should check out this page as it goes into the UObject architecture (which is where that constructor comes from):

Basically, anything that inherits from UObject (AActor, etc) needs to implement that UObject default constructor that takes in the FObjectInitializer parameter.

When in doubt, read the header files of the classes you are inheriting from and see how their constructors are laid out.

That’s how I knew which Octree constructor you needed to use.

	/** Initialization constructor. */
	TOctree(const FVector& InOrigin,float InExtent);

#if WITH_HOT_RELOAD_CTORS
	/** DO NOT USE. This constructor is for internal usage only for hot-reload purposes. */
	TOctree();
#endif // WITH_HOT_RELOAD_CTORS
1 Like

This was exactly what I was looking for.

Thanks again for all your help @AdeptStrain,

Farshooter