Some people prefer "{}" over "()" within a constructor, cause it's close to default variable initialization. Yet Unreal has issues with it.
Example 1 - No Unreal Reflection System // will work
struct FMyConstructorExample
{
FMyConstructorExample() = default;
explicit FMyConstructorExample(const int32 SomeNumberIn) : SomeNumber{SomeNumberIn} {}
int32 SomeNumber;
};
Example 2 - With Unreal Reflection System // won't work
#include "FMyConstructorExample.generated.h"
USTRUCT()
struct FMyConstructorExample
{
GENERATED_BODY()
FMyConstructorExample() = default;
explicit FMyConstructorExample(const int32 SomeNumberIn) : SomeNumber{SomeNumberIn} {}
int32 SomeNumber;
};
Example 3 - With Unreal Reflection System and "()" // will work
#include "FMyConstructorExample.generated.h"
USTRUCT()
struct FMyConstructorExample
{
GENERATED_BODY()
FMyConstructorExample() = default;
explicit FMyConstructorExample(const int32 SomeNumberIn) : SomeNumber(SomeNumberIn) {}
int32 SomeNumber;
};
So here it's all up to personal preference. But for consistency, "()" may be preferred unless you don't use Unreal types too often.
By default, Unreal does not allow deleting the default constructor when using its reflection system. In some cases this is desired behavior and fine, yet if you want to only allow an explicit constructor for safety, it will hinder you.
Example 1 - No Unreal Reflection System // will work
struct FMyReflexionExample
{
FMyReflexionExample() = delete;
explicit FMyReflexionExample(const int32 SomeNumberIn) : SomeNumber(SomeNumberIn) {}
int32 SomeNumber;
};
Example 2 - With Reflection System // won't work
#include "FMyReflexionExample.generated.h"
USTRUCT()
struct FMyReflexionExample
{
GENERATED_BODY()
FMyReflexionExample() = delete;
explicit FMyReflexionExample(const int32 SomeNumberIn) : SomeNumber(SomeNumberIn) {}
int32 SomeNumber;
};
So you have to choose: do you need the reflection system? If no, does deleting the default constructor actually add something to it like the security of an explicity initialization?
Example 3 - The Workaround (best and worst of both worlds) // will work
#include "FMyReflexionExample.generated.h"
USTRUCT()
struct FMyReflexionExample
{
GENERATED_BODY()
FMyReflexionExample() = default;
explicit FMyReflexionExample(const int32 SomeNumberIn) : SomeNumber(SomeNumberIn) {}
int32 SomeNumber;
};
Of course, if it's a simple type, you can just set it to 0. Yet when using for example pointers, you'd have to do some extra leg-work. Additionally you could also make a static function for safely creating the struct in this example, but that comes down to preference.