How to declare a Custom Struct as new variable in C++

Hi everyone,

I encountered a weird problem.

I want to declare a struct in the same class header file I defined it. But it doesn’t like the way I declared it and says “unrecognized class type” in the error message.

I want to declare this struct that I defined, so that I can access it from Blueprint when I use the node “GetClassDefault”

If I declare this struct as a new variable in BP, GetClassDefault will show my struct in the node, however it doesn’t show this if I just define it in C++.

I think there should be a very easy solution, just that I’m completely ignorant on how struct works in C++.

Thank you so much for the help!

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "SkillMaster.generated.h"

UCLASS()
class RENOVA_API ASkillMaster : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	ASkillMaster();

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FSkillData SkillData;

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	
	
};

//Use USTRUCT(BlueprintType) if you would like to include your Struct in Blueprints
USTRUCT(BlueprintType)
struct RENOVA_API FSkillData
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FString Name;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FString Description;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	float CD;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	float CastTime;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	bool bInterruptable;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	bool bRequireTarget;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	UTexture2D* SkillIcon;

};

Hi teutonicdesign,

I do usually declare USTRUCTs in dedicated header files, they work beautifully. There’s a difference I can see in that approach from yours that might be the source of your issue; when I declare my USTRUCT in a dedicate file, I have on top, as last include, #include “Nameofmystruct.generated.h”

That include is missing in your file – you got a .generated.h for skillmaster, but not for FSkillData. I don’t know whether you can include two .generated.h in the same file, I’d try, and if it doesn’t work, probably the easiest solution is just to have FSkillData in its own header file, and include it in skillmaster.

Let me know if that helps!

f

This did solve the problem! Yes it won’t allow me to have two #include “xxx.generated.h” so I defined the struct in its own header file and now things work great!

I thought defining the struct in another class would be easier, but now I see it’s still better to use a dedicated file.

The way you explain things is very neat and organized, made it much easier for me to grasp the issue.

Thanks a lot!