Trouble instantiating new struct

Hi All

I have a struct as follows;

USTRUCT(BlueprintType)
struct FMyStruct
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Blah)
		FName Key;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Blah)
		float Value;

	FMyStruct(FName NewKey, float NewValue) {

		Key = NewKey;
		Value = NewValue;
	}

};

And then I’m trying to instantiate a pointer to a new struct by going;

FMyStruct* NewStruct = new FMyStruct(NewKey, NewValue);

This isn’t working- I’m getting a “C2512 no appropriate default constructor” error. Anyone know what I’m doing wrong?

Thanks!!!

Try having a default constructor, something along the lines of:
FMyStruct() {}

In your header. I think for it to be instantiated inside blueprints it needs a default.

Well, I’ve got it working by removing the constructor from inside the struct definition, and then creating a new one with no arguments. And then assigning key->newkey etc immediately afterwards. But I don’t understand why the constructor in this definition doesnt work. Maybe it’s because its a blueprinttype???

Nope, removed Blueprinttype and it still doesnt work. Just have to use normal constructor and add properties afterwards…

Did you try:

FMyStruct NewStruct(NewKey, NewValue);

?

No but now you mention it, it seems like it would work.

FMyStruct* NewPointer;
FMyStruct NewStruct(NewKey, NewValue);
NewPointer = &NewStruct;

Either way its 3 lines of code. I haven’t started debugging what I’m doing yet so if there’s a problem with the former, I’ll try this! Thankyou!