1

Hello dear Community!

I have copypasted my own source files I wrote outside of Unreal into the "private" (for cpp-files) and the "public" (for my header files) folders of an unreal-C++-Project, so I can include my own custom classes in my unreal source files.

It works as it should, but I want to use my own enums, that are obviously defined in my own non-Unreal-specific Files, as UEnums, so I have to modify them there with Unreal-specific Macros.

Will Unreal Header Tool incorporate my own Files or only the ones I created from the Unreal Editor? And do I need to write a "...generated.h"-include in my own custom headers I wrote outside of Unreal?

Thank you so much in advance!

I did this:

  • first I added a generated.h. My File is named like "File.h", and I added a generated.h-include in it like this:
#include "File.generated.h"

Of course as the last include, as it should be.

  • Then I added the Unreal-Macros to the enum. It went from this:
enum MyEnum {
    FIRST_ENTRY,
    SECOND_ENTRY
};

to this:

UENUM(BlueprintType, Category="Enums")
enum MyEnum {
    FIRST_ENTRY UMETA(DisplayName="First Entry"),
    SECOND_ENTRY UMETA(DisplayName="Second Entry")
};
  • Then I tried to incorporate a variable with this Enum type as a UProperty in one of my Unreal-Classes like this:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
    TEnumAsByte<MyEnum> EnumVariable;

Sadly I get an Error:

"Error: Expected the name of a previously defined enum"

Of course I included the Header File with my Enum before, so this cannot be the reason I guess.

Skyseed
  • 11
  • 3
  • 1
    please read about [mcve] – 463035818_is_not_an_ai Jun 19 '23 at 11:50
  • It is in an Unreal-C++-Project, and of course I am depending on Unreals API and Unreal Header Tool, how would someone try to reproduce my Problem? I am hoping for people who had run in the same problem to share their knowledge. – Skyseed Jun 19 '23 at 12:00
  • i am not familiar with unreal. Though rather than explaining how your code looks like ("Of course I included the Header File with my Enum before,..") it is better to show the code. Also the error message looks incomplete – 463035818_is_not_an_ai Jun 19 '23 at 12:02
  • Exactly, the first half of the Error message consists of the path to the file and the line. Sadly I cannot share the files themselves for copyright reasons. – Skyseed Jun 19 '23 at 12:08
  • 1
    "Sadly I cannot share the files themselves for copyright reasons." and thats exactly where the MRE comes in. Its code that you can share, because it has nothing about copyright, but all about the same issue as your actual code. – 463035818_is_not_an_ai Jun 19 '23 at 12:13
  • But thank you for your will to help, I appreciate that! Maybe someone else sees this question with a little knowledge about Unreal, it seems to be a pretty basic problem. – Skyseed Jun 19 '23 at 12:14
  • @Skyseed Windows or MacOS? – karlphillip Jun 21 '23 at 00:13
  • I'm using Windows. – Skyseed Jun 24 '23 at 10:37

1 Answers1

0

I believe the solution is the same for UE4 and UE5. These files can be created automatically by running the GenerateProjectFiles script to generate new project files:

~/UnrealEngine4.27/UnrealEngine-4.27.2-release/GenerateProjectFiles.sh ~/Documents/Unreal\ Projects/TestProject/TestProject.uproject -Game

On Windows the script would be in a different location, of course, and you would have to run the .bat version.

Anyway, here is the official documentation.

karlphillip
  • 92,053
  • 36
  • 243
  • 426