How do I add a standalone .h file for a struct?

I can’t figure out how to properly add just a plain standalone .h file into my project so that it properly hooks into Unreal. I can add new classes using the wizard from the editor and that hooks them in automatically, but how can I do the same without using the wizard?

I want to define a struct in a standalone header, rather than in an existing class file for organizational purposes.

hi,
the way i add my files is by copying all files to the /projectfolder/source/projectname/ folder and then rightclick the unreal project file and hit regenerate visual studio files

Assuming your file is called MyStruct.h:



// Your copyright
#pragma once
#include "SomeOther.h"
#include "MyStruct.generated.h" // this must be last include in the file

USTRUCT()
struct FMyStruct
{
    GENERATED_USTRUCT_BODY()
    // add stuff you'd like to
};

You also must supply a .cpp file. It will be like this:



// Your copyright
#include "YourProjectName.h" // this header is typically inside your project's source root directory
#include "MyStruct.h"
// add stuff you'd like to

Then you should regenerate project file and build.

The way I do it is without and cpp.

  1. Copy a header file in your “source/projectname/” - folder
  2. Rename it the way you want.
  3. open vs rightclick your project and “add existing item”

works for me fine. every enum and struct are collected in a few header files.

cheers

This is the “normal” way and the first thing I tried, but none of the UE4 macros like USTRUCT(), UPROPERTY() etc were working.

I will try the regenerate project trick guys, thanks.