New to C++, Need help with some 'probably simple to fix' errors

I recently decided that it would be a good idea to create my own plugin for personal use between different projects I have planned. I have only ever dealt with Blueprints so far in unreal, but I wanted to branch out into C++ to try and expand what is possible.

Inside of my plugin, i knew that i was going to be using a lot of Enumerations, so I figured I would take this as an opportunity to learn some C++. I have recently been looking through some source code for other plugins i own, so try to piece some things together, and I noticed that in one plugin, they were simply using a .h file to store all of the Enums they needed.

I created a C++ file in my plugin public source folder and gave it an appropriate name, and then proceeded to follow the format that i could see from the reference Enum .h file I had been looking at.

My issue is that my project builds perfectly fine, and when i open the unreal editor, my Enums are available to use in blueprints. But in Visual studio, almost all of my code is showing errors.

This is the code that i have (it has a few more enums, but i removed them just to keep the length down. Also, the file that i was using as a reference also has “#include <CoreMinimal.h>” inside of it before the generated.h include, but that just added an extra like 500 more errors, so i removed it and it still seemed to build just fine.

#pragma once

#include "HC_LevelEditor_Enums.generated.h"


//Reset Types
UENUM(BlueprintType)
enum class EResetType : uint8
{
	LevelReset,
	CheckpointReset
};


//Distance Operations
UENUM(BlueprintType)
enum class EDistanceOperations : uint8
{
	World,
	Plane,
	Height
};

The main error seems to be from the “#include “HC_LevelEditor_Enums.generated.h”” as it says “cannot open source file “HC_LevelEditor_Enums.generated.h””

After that, basically everything else is just throwing an error:

Also just in case its important, here is a pic of my file structure also:
UE5Error02

I appreciate any help that can be given, thanks! <3

I’m guessing you originally had the HC_LevelEditor_Enums.h file generated with a matching HC_LevelEditor_Enums.cpp? Without that .cpp file, you don’t get a generated file.

Basically, delete:

#include "HC_LevelEditor_Enums.generated.h"

and put

#include "CoreMinimal.h"

back in.

As an example, here’s the top of an enumeration header from one of my own projects (and the first enumeration). The file only contains various type enumerations for this module.

#pragma once
#include "CoreMinimal.h"

UENUM(BlueprintType)
enum class EVelociwrapperInputType : uint8
{
	EVIT_ForwardAxis	= 0		UMETA(DisplayName = "Forward Axis"),
	EVIT_RightAxis		= 1		UMETA(DisplayName = "Right Axis"),
	EVIT_Turn			= 2		UMETA(DisplayName = "Turn"),
	EVIT_LookUp			= 3		UMETA(DisplayName = "Look Up"),
	EVIT_Sprint			= 4		UMETA(DisplayName = "Sprint"),
	EVIT_FreeRun		= 5		UMETA(DisplayName = "Free Running"),
	EVIT_Jump			= 6		UMETA(DisplayName = "Jump")
};

There’s no .cpp file to go with this file, so no .generated.h include.

(And no, I’m not sorry in the least for wrapping parkour-related movement – thus, y’know, velocity and all – in a module called “Velociwrapper”. Never regret a terrible pun.)

1 Like

having a:

#include "SomeName.generated.h"

in your header without a SomeName.cpp file does not generate an error.
Sometimes VS can throw an error message unrelated to an actual problem, which is usually the case when there is a syntax error somewhere or a problem related to a UFUNCTION or UPROPERTY macro. It’s worth noting that VS is a bit paranoid as well if you show intellisense errors.

Ah That is good information to know. I actually just dropped a new notepad text file into my source folder and then in VS i changed the name and the file type to the .h file, so I didn’t have a cpp file to go with it. I was just following the format of an existing file I found with enums in it which had the generated.h include inside of it.

Once i re-add the “#include “CoreMinimal.h”” i get a few new errors:

And i still have a bunch of errors pertaining to my Enums that i have made:

Appreciate the help so far and i actually love the pun lmao xD

First, change the Build + Intellisense on the dropdown to “Build”. Then build the project. any errors remaining indicate there is a problem.

If the build’s truly failing, not just Intellisense screaming into the void (as @Roy_Wierer.Seda145 notes)… then just to double-check, in your plugin’s <whatever>.Build.cs file, what do you have as your dependencies?

For instance, I have:

PublicDependencyModuleNames.AddRange(
	new string[]
	{
		"Core",
		/* other unrelated dependencies */
	}
);

PrivateDependencyModuleNames.AddRange(
	new string[]
	{
		"CoreUObject",
		"Engine",
		/* other unrelated dependencies */
	}
);

@Roy_Wierer.Seda145 Thank you, this cleared all of the errors so i guess its probably ok now :slight_smile:

@Packetdancer For my includes i have

using UnrealBuildTool;

public class HC_LevelEditor : ModuleRules
{
	public HC_LevelEditor(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
		
		PublicIncludePaths.AddRange(
			new string[] {
				// ... add public include paths required here ...
			}
			);
				
		
		PrivateIncludePaths.AddRange(
			new string[] {
				// ... add other private include paths required here ...
			}
			);
			
		
		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				// ... add other public dependencies that you statically link with here ...
			}
			);
			
		
		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				"CoreUObject",
				"Engine",
				"Slate",
				"SlateCore",
				// ... add private dependencies that you statically link with here ...	
			}
			);
		
		
		DynamicallyLoadedModuleNames.AddRange(
			new string[]
			{
				// ... add any modules that your module loads dynamically here ...
			}
			);
	}
}

The build is successful though, its just that the errors were worrying me. Switching the errors to show only build only removed all of them though.

If there are no build errors it is totally fine. Intellisense isn’t that intelligent.

1 Like

Note, Documentation (if any) is a bit vague on .generated.h files. Assume that any time you work with a header containing UCLASS, USTRUCT, UENUM, UFUNCTION etc. that you simply need to #include the .generated version of the header as the last include on the list. I can’t tell what the result is of not doing this, I just remember it is a requirement.

Excellent, I really appreciate the helps guys <3

Hi guys! Newbie here, thanks for accepting me.