Quick answer: C2065 means the compiler reached a name that nothing above that line has declared. In Unreal C++ the usual cause is a missing #include, because CoreMinimal.h and your parent class header do not bring in gameplay classes such as UGameplayStatics or UCameraComponent. The other causes are a typo, an enum value used without its scope, a log category that was never declared, and a member that only exists inside #if WITH_EDITOR. Fix the first error in the Output window and rebuild, because the errors after it are often fallout.

You build an Unreal project and the compiler says a class, a variable or a macro is an undeclared identifier, sometimes for a name you can see in the engine documentation. Often the same file compiled yesterday, or still compiles on a teammate’s machine. This guide covers what the error means, the two sibling errors that have the same cause, how to find the right header, why Unreal’s build system hides missing includes until a bad moment, and the cases that have nothing to do with includes.

The exact error

From Visual Studio’s Output window, or from the editor’s compile log:

D:\Projects\MyGame\Source\MyGame\HeroCharacter.cpp(41): error C2065: 'AEnemy': undeclared identifier
D:\Projects\MyGame\Source\MyGame\HeroCharacter.cpp(41): error C2065: 'Target': undeclared identifier
D:\Projects\MyGame\Source\MyGame\HeroCharacter.cpp(58): error C2065: 'LogHero': undeclared identifier

Two neighbors come from the same causes and take the same fixes. MSVC picks the code from how the unknown name is used:

HeroCharacter.cpp(63): error C2653: 'UGameplayStatics': is not a class or namespace name
HeroCharacter.cpp(63): error C3861: 'GetPlayerPawn': identifier not found
HeroCharacter.cpp(70): error C3861: 'DOREPLIFETIME': identifier not found

A bare name or a type gives C2065. A name in front of :: gives C2653. A name called like a function, which includes a macro whose header is missing, gives C3861. On Mac, Linux, Android and any other platform built with Clang, one message covers all three, with unknown type name as a variant when the name appears where only a type can go:

HeroCharacter.cpp:41:2: error: use of undeclared identifier 'AEnemy'
HeroCharacter.cpp:63:17: error: use of undeclared identifier 'UGameplayStatics'

What the compiler is telling you

C++ compiles each .cpp file on its own, from top to bottom. A name can be used only after its declaration has been read, either earlier in the file or in a header included above the line. Nothing is looked up across the project. The fact that AEnemy exists in Enemy.h two folders away means nothing to HeroCharacter.cpp until that header is included.

The compiler does not stop at the first unknown name. In the example above, line 41 is AEnemy* Target = Cast<AEnemy>(OtherActor);. Because AEnemy is unknown, the line is not understood as a declaration, so Target is reported as undeclared too, and every later line that uses Target adds another error. One missing include can produce twenty errors. Always work from the first one.

The common causes

What you seeCauseFix
An engine class, function or macro is unknown: UGameplayStatics, UCameraComponent, DrawDebugLine, DOREPLIFETIMEIts header is not included in this fileAdd the include (Fix 1)
One of your own classes is unknownIts header is not included, or two of your headers include each otherInclude it in the .cpp; forward declare in headers
The file compiled before, or compiles for someone elseA unity build or the shared precompiled header was supplying the includeAdd the include anyway (see below)
The name is nearly rightTypo or wrong case: UGamePlayStatics, Gengine, health for HealthCorrect the spelling; C++ is case sensitive
Idle, Walking or another enum value is unknownThe value belongs to an enum class and needs its scopeEWeaponState::Idle
The first argument of UE_LOG is unknownThe log category was never declared, or its header is not includedDECLARE_LOG_CATEGORY_EXTERN and DEFINE_LOG_CATEGORY
The editor builds, packaging failsThe member is declared inside #if WITH_EDITOR or #if WITH_EDITORONLY_DATAGuard the code that uses it the same way (Fix 3)
Errors appeared after an engine upgradeAn engine header stopped including another header for youInclude the header that declares the name
Red underlines and entries in the Error List, but the build succeedsIntelliSense, not the compilerRead the Output window

Read the Output window, not the Error List

Visual Studio’s Error List mixes two sources: the compiler and IntelliSense. IntelliSense parses Unreal code with its own engine, lags behind generated headers, and reports problems that do not exist. Its entries have codes that start with E, such as E0020 identifier "UGameplayStatics" is undefined. Compiler errors start with C.

  1. In the Error List, change the dropdown from Build + IntelliSense to Build Only.
  2. Open View > Output and set Show output from to Build. This is the real compiler output, in order.
  3. Scroll to the first line containing error. Double-click it to jump to the file and line.

If the build reports success and only E entries remain, there is nothing to fix in the code. Regenerating project files usually clears stale IntelliSense state; How to Fix IntelliSense Not Working for Your Game Code covers the rest.

Fix 1: add the missing include

Broken:

// HeroCharacter.cpp
#include "HeroCharacter.h"

void AHeroCharacter::FaceNearestEnemy()
{
	TArray<AActor*> Found;
	UGameplayStatics::GetAllActorsOfClass(this, AEnemy::StaticClass(), Found);   // C2653, C3861
}

Fixed:

// HeroCharacter.cpp
#include "HeroCharacter.h"              // matching header first
#include "Enemy.h"                      // AEnemy
#include "Kismet/GameplayStatics.h"     // UGameplayStatics

Unreal follows a convention called include what you use: every file includes the headers for the things it names, and nothing relies on one giant engine header. CoreMinimal.h covers the Core module only: strings, names, containers, math types, delegates and the logging macros. It contains no actor, component or gameplay class. Your parent class header, such as GameFramework/Character.h, brings in the parent and forward declares a few related types, which is enough to store pointers to them and not enough to use them.

To find the header for a name you do not know:

The ones that come up most:

NameIncludeModule
UGameplayStaticsKismet/GameplayStatics.hEngine
UKismetMathLibraryKismet/KismetMathLibrary.hEngine
UKismetSystemLibraryKismet/KismetSystemLibrary.hEngine
GEngine, UEngineEngine/Engine.hEngine
UWorldEngine/World.hEngine
DOREPLIFETIME and its variantsNet/UnrealNetwork.hEngine
DrawDebugLine, DrawDebugSphereDrawDebugHelpers.hEngine
FTimerManagerTimerManager.hEngine
TActorIteratorEngineUtils.hEngine
FDamageEvent, FPointDamageEventEngine/DamageEvents.hEngine
UCameraComponentCamera/CameraComponent.hEngine
USpringArmComponentGameFramework/SpringArmComponent.hEngine
UCharacterMovementComponentGameFramework/CharacterMovementComponent.hEngine
UCapsuleComponentComponents/CapsuleComponent.hEngine
ConstructorHelpersUObject/ConstructorHelpers.hCoreUObject
UUserWidgetBlueprint/UserWidget.hUMG
UEnhancedInputComponentEnhancedInputComponent.hEnhancedInput
UNiagaraFunctionLibraryNiagaraFunctionLibrary.hNiagara
AAIControllerAIController.hAIModule
UNavigationSystemV1NavigationSystem.hNavigationSystem
FGameplayTagGameplayTagContainer.hGameplayTags

When the module in the last column is not Core, CoreUObject or Engine, it also has to be listed in your module’s Build.cs. Without that, the include itself fails with fatal error C1083, or the code compiles and the linker reports LNK2019.

In headers, prefer a forward declaration (class UCameraComponent;) for anything held by pointer, and put the include in the .cpp. That removes C2065 from the header without making every file that includes it pay for another include. If the next build then reports that the type is undefined, that is error C2027, and it means the .cpp still needs the real header. If the unknown type is on a UPROPERTY line, Unreal Header Tool usually stops first with Unrecognized type.

Why it compiled yesterday, or on another machine

A file with a missing include can build for months. Three parts of Unreal Build Tool (UBT) make that possible.

Engine upgrades are the fourth reason. Epic removes indirect includes from engine headers over time, and the IncludeOrderVersion setting in your Target.cs files decides which of the old ones are still provided. Raising it, or moving to a newer engine, makes names that used to arrive by accident stop being declared. FDamageEvent is a typical example: it lives in Engine/DamageEvents.h, and older include orders pulled it in through Engine/EngineTypes.h.

The fix in every case is the same include you would have needed anyway. To find all such files at once instead of one per week, build once with unity and precompiled headers off. In both MyGame.Target.cs and MyGameEditor.Target.cs, temporarily add:

bUseUnityBuild = false;
bUsePCHFiles = false;

To limit the test to one module, put bUseUnity = false; and PCHUsage = PCHUsageMode.NoPCHs; in that module’s Build.cs instead. When you run UBT yourself, the switches -DisableUnity -NoPCH do the same. The build is much slower, so revert the change once the errors are fixed. Running this before you hand a plugin to someone else saves them from finding your missing includes.

Fix 2: spelling, scope, enums and log categories

Spelling and case. UGamePlayStatics, FVector3, GetactorLocation. Class prefixes count as part of the name: the class is AEnemy, the file is Enemy.h, and the Blueprint-visible name is Enemy. Clang often prints a suggestion with the correct spelling; MSVC does not.

Scope. A variable declared inside an if or for block does not exist after the closing brace. Declare it before the block.

Enum values. Unreal enums are normally declared as enum class, and their values are not visible without the enum’s name:

UENUM(BlueprintType)
enum class EWeaponState : uint8
{
	Idle,
	Firing,
	Reloading
};

State = Idle;                  // error C2065: 'Idle': undeclared identifier
State = EWeaponState::Idle;    // correct

Log categories. UE_LOG(LogHero, Warning, TEXT("...")) needs LogHero to be declared. LogTemp arrives with CoreMinimal.h. A category of your own has to be declared in a header and defined in exactly one .cpp:

// MyGame.h
#include "CoreMinimal.h"

DECLARE_LOG_CATEGORY_EXTERN(LogHero, Log, All);
// MyGame.cpp
#include "MyGame.h"

DEFINE_LOG_CATEGORY(LogHero);

Every file that logs to LogHero then includes MyGame.h. If you declare the category and forget the DEFINE_LOG_CATEGORY line, C2065 goes away and the linker fails with an unresolved external instead.

Fix 3: members that exist only in the editor

This is the version that passes every editor build and breaks packaging. A member declared inside an editor-only block is removed from the class when the game target is compiled:

// Pickup.h
UPROPERTY(EditAnywhere)
int32 Value = 10;

#if WITH_EDITORONLY_DATA
	UPROPERTY(EditAnywhere, Category = "Debug")
	FString DesignerNote;
#endif
// Pickup.cpp
void APickup::BeginPlay()
{
	Super::BeginPlay();
	UE_LOG(LogTemp, Log, TEXT("Note: %s"), *DesignerNote);   // editor: fine. Packaged: C2065
}

In the packaged build DesignerNote is not a member, so the name is undeclared. The same happens with functions declared inside #if WITH_EDITOR, such as an override of PostEditChangeProperty or a helper it calls. Either guard the use with the same condition, or move the member out of the block if the game needs it:

#if WITH_EDITORONLY_DATA
	UE_LOG(LogTemp, Log, TEXT("Note: %s"), *DesignerNote);
#endif

Use WITH_EDITORONLY_DATA around data members and WITH_EDITOR around code. The error arrives late because nothing compiles the game target until you package. Build the Development configuration (without “Editor”) from the IDE before a long cook, and the compiler tells you in a minute what packaging would tell you in thirty. If the failure reaches you through the packaging log, How to Fix “Packaging failed” in Unreal Engine shows how to find the compiler line in it.

Confirm the fix

  1. Build Development Editor from the IDE. The Output window should end with a line saying the build succeeded, with no C2065, C2653 or C3861 above it.
  2. Build the Development game configuration once. It catches editor-only members.
  3. If the code is shared with other projects or other people, do one build with unity and precompiled headers off.
  4. If you build for a Clang platform, build that target too. Clang and MSVC do not always agree on which names are visible, mostly inside templates, so a file can pass on Windows and fail there.

Where Bugnet fits, and where it does not

A compile error never reaches Bugnet. It stops the build on your machine, no executable is produced, and no player or tester ever sees it. Bugnet is a runtime tool and has no part in fixing C2065.

What can reach players is the way the error gets silenced. A #if WITH_EDITOR guard added in a hurry removes that code from the packaged game, and behavior that worked in the editor is now missing in the build people play. That kind of regression shows up at runtime as a failed check, a failed ensure or a fatal error. Bugnet’s Unreal SDK files those with the engine’s error text and recent log lines, and each report carries the game version, so you can see that the problem started with the build that contained the fix. Setup is in the getting started guide.

Frequently asked questions

What does error C2065 undeclared identifier mean in Unreal Engine?

The compiler reached a name that nothing above that line in the file has declared. In Unreal C++ the usual cause is that the header declaring the class, function or macro is not included in that file. Typos, enum values used without their scope and undeclared log categories produce the same error.

Which header do I include for UGameplayStatics or GEngine?

UGameplayStatics is declared in Kismet/GameplayStatics.h and GEngine in Engine/Engine.h, both in the Engine module. For any other class, its page in the C++ API reference lists the include line, and engine headers are named after the class without its A or U prefix.

Why does my Unreal project compile in the editor but fail with C2065 when packaging?

The name is declared inside an #if WITH_EDITOR or #if WITH_EDITORONLY_DATA block, so it does not exist when the game target is compiled. Wrap the code that uses it in the same condition, or move the declaration out of the block if the game needs it. Building the Development game configuration from the IDE shows the error without a full package.

Why did C2065 appear in a file I did not change, or only on another machine?

Unity builds merge source files, so a file can borrow an include from another file in the same merged unit, and the shared precompiled header supplies many engine headers. Adding or removing files, editing the file, building without precompiled headers or upgrading the engine removes the borrowed include. Add the include the file needed all along.

Why does Visual Studio show undeclared identifier errors when the build succeeds?

Those entries come from IntelliSense, not from the compiler. Their codes start with E, such as E0020, while compiler errors start with C. Set the Error List filter to Build Only and read the Output window to see what the compiler reported.

An undeclared identifier is almost always a missing include, and Unreal’s unity builds and shared precompiled header can hide that for months. Include the header for every name a file uses, and fix the first error in the Output window before reading the rest.