How to create a simple USTRUCT in c++?

Hi, I have tried to create a simple USTRUCT in c++.
I created a new header file called MyStruct.h


#pragma once

#include "CoreMinimal.h"
#include "MyStruct.generated.h"

USTRUCT(BlueprintType)
struct MyStruct
{
    GENERATED_BODY()

        UPROPERTY(BlueprintReadWrite)
        int myNumber;
};

It complains that i does not know what USTRUCT is. And refuses to compile.
I cant find any info on how this is set up. Please help :slight_smile:

My errors:
E0077 this declaration has no storage class or type specifier (for the USTRUCT keyword)
E0020 identifier “BlueprintType” is undefined

If you haven’t already, close out of the editor and VS, and then right click on the uproject file and click Generate Visual Studio Files. Then re-open VS and you should be good.

When you create a new header file, you need to let the engine create the generated.h file. This is how you do that.

All Structs need to be prefixed with F, and you shouldn’t use native CPP types. The struct should be declared like this:



USTRUCT(BlueprintType)
struct FMyStruct
{
    GENERATED_BODY()
public:
    UPROPERTY(BlueprintReadWrite)
    int32 myNumber;
};


You DO NOT need to close and regenerate project files each time you create a new header! This is a common misconception - UHT will recreate the generated headers that it needs to everytime you build the project.

Thanks for your suggestions. Unfortunatly, neither fixed my issue.
Visual Studio asks me if I want to reimport the files after I generate them.
Unfortunatly, the generated header file remains non-existant.
(Could this be because I inherit from Object and dont inherit from Actor?)