Which (const FObjectInitializer& ObjectInitializer) is correct?

Hey there!

I’m very new to both UE4 and C++, and while having to learn on 4.8 I’ve come across the new constructor definition we’re supposed to use with GENERATED_BODY, but I keep coming across different versions. Which one is right, or when would I use one or the other? Any help is greatly appreciated! Thanks in advance!

  1. ATestCharacter::ATestCharacter(const FObjectInitializer& ObjectInitializer)
  2. ATestCharacter::ATestCharacter(const FObjectInitializer& ObjectInitializer) :Super(ObjectInitializer)
  3. ATestCharacter::ATestCharacter(const class FObjectInitializer& ObjectInitializer)
  4. ATestCharacter::ATestCharacter(const class FObjectInitializer& ObjectInitializer) :Super(ObjectInitializer)

Hello, Jibberish

Keyword class in this context means that the class being used may not be defined at this point, but there is a definition, so compiler won’t classify class name as undefined. However, FObjectInitializer is usually defined in your Unreal Engine 4 project, so you can just use const FObjectInitializer& ObjectInitializer).

Please note that the super class constructor call should usually be performed, because most of the time in the Unreal Engine 4 you will work with classes, that inherit the existing ones. Thus, :Super(ObjectInitializer) should be used.

Hope this helped!

Have a great day!

Thanks, that helped a lot. Have an up-boat!