Having trouble with new, empty header file and structs

Hi,

I’m trying to create a global struct, but I cant get it to work.

I Added a new C++ file with the Editor Function “Add New C++ File” and chosed “None” as base class.

The .cpp is empty.

.h:


#pragma once

#include "Engine.h"
#include "Spaceship_Structs.generated.h";

USTRUCT()
struct FTest
{
    GENERATED_USTRUCT_BODY()

    int Var1;
    int Var2;
};

With this Code, i get the following error messages:


1>D:\Unreal Projects\Spaceship\Source\Spaceship\Public\Spaceship_Structs.h(6): error C4067: unexpected tokens following preprocessor directive - expected a newline
1>D:\Unreal Projects\Spaceship\Source\Spaceship\Public\Spaceship_Structs.h(6): error C4067: unexpected tokens following preprocessor directive - expected a newline


If I remove the .generated.h, i get the following error messages (Line 13 is the GENERATED_USTRUCT_BODY() makro):


1>D:\Unreal Projects\Spaceship\Source\Spaceship\Public\Spaceship_Structs.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

I already removed the .vs, Binaries, Intermediate and Saved folder and .sln file and generated the visual studio project files via right click on the .uproject file, but it still does not work.

I couldn’t find any other things to do. Does anyone has an idea whats wrong here?

Thanks in advance!

Get rid of the semicolon after "#include “Spaceship_Structs.generated.h”

Here is a properly formed struct:

USTRUCT()
struct FInterpolationAnimation
{
GENERATED_BODY()

 UPROPERTY(EditAnywhere)
 FVector Location;

 UPROPERTY(EditAnywhere)
 FRotator Rotation;

};

2 Likes

Oh my god… Thank you Jacko! It compiles now. I searched for hours… I just didn’t saw that.

1 Like

Engine.h is a massive header - unless you really need it in the header, I’d advise removing it.

2 Likes

Yes, replace Engine.h with CoreMinimal.h.

1 Like

Late reply here, but I’ve noticed deleting “include CoreMinimal.h” from every file has no effect on the project. Not sure why adding a class through the editor always puts that include in. :face_with_monocle: