How to write constructor for custom struct

Just to add to this if you end up here and you’re still getting “no default constructor” or linking errors:

It seems that you always need to set default values of all your struct variables in your constructor. In my case, I did one default constructor with no arguments, initialising all variables to something:

FMyConstructor()
{
     Variable1 = 0;
     Variable2 = nullptr;
     veriable3 = EMyEnum::SomeEnum;
    // etc
}

Then the way I wanted to use it in code:

FMyConstructor(float var1, AActor* var2, TEnumAsByte<MyEnum> var3)
{
    variable1 = var1;
    variable2 = var2;
    variable3 = var3;
}

Finally compiles on my end!

4 Likes