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
- What the compiler is telling you
- The common causes
- Read the Output window, not the Error List
- Fix 1: add the missing include
- Why it compiled yesterday, or on another machine
- Fix 2: spelling, scope, enums and log categories
- Fix 3: members that exist only in the editor
- Confirm the fix
- Where Bugnet fits, and where it does not
- Related guides
- Frequently asked questions
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 see | Cause | Fix |
|---|---|---|
An engine class, function or macro is unknown: UGameplayStatics, UCameraComponent, DrawDebugLine, DOREPLIFETIME | Its header is not included in this file | Add the include (Fix 1) |
| One of your own classes is unknown | Its header is not included, or two of your headers include each other | Include it in the .cpp; forward declare in headers |
| The file compiled before, or compiles for someone else | A unity build or the shared precompiled header was supplying the include | Add the include anyway (see below) |
| The name is nearly right | Typo or wrong case: UGamePlayStatics, Gengine, health for Health | Correct the spelling; C++ is case sensitive |
Idle, Walking or another enum value is unknown | The value belongs to an enum class and needs its scope | EWeaponState::Idle |
The first argument of UE_LOG is unknown | The log category was never declared, or its header is not included | DECLARE_LOG_CATEGORY_EXTERN and DEFINE_LOG_CATEGORY |
| The editor builds, packaging fails | The member is declared inside #if WITH_EDITOR or #if WITH_EDITORONLY_DATA | Guard the code that uses it the same way (Fix 3) |
| Errors appeared after an engine upgrade | An engine header stopped including another header for you | Include the header that declares the name |
| Red underlines and entries in the Error List, but the build succeeds | IntelliSense, not the compiler | Read 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.
- In the Error List, change the dropdown from Build + IntelliSense to Build Only.
- Open View > Output and set Show output from to Build. This is the real compiler output, in order.
- 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:
- Look the class up in Epic’s C++ API reference. Each class page lists the module, the header path and the exact include line.
- Engine class headers are named after the class without its prefix:
UCameraComponentlives inCameraComponent.h. Search the engine source for that file name. The include path is the part after the module’sPublicorClassesfolder. - In the IDE, use Go To Definition (F12) on a place where the name already works.
The ones that come up most:
| Name | Include | Module |
|---|---|---|
UGameplayStatics | Kismet/GameplayStatics.h | Engine |
UKismetMathLibrary | Kismet/KismetMathLibrary.h | Engine |
UKismetSystemLibrary | Kismet/KismetSystemLibrary.h | Engine |
GEngine, UEngine | Engine/Engine.h | Engine |
UWorld | Engine/World.h | Engine |
DOREPLIFETIME and its variants | Net/UnrealNetwork.h | Engine |
DrawDebugLine, DrawDebugSphere | DrawDebugHelpers.h | Engine |
FTimerManager | TimerManager.h | Engine |
TActorIterator | EngineUtils.h | Engine |
FDamageEvent, FPointDamageEvent | Engine/DamageEvents.h | Engine |
UCameraComponent | Camera/CameraComponent.h | Engine |
USpringArmComponent | GameFramework/SpringArmComponent.h | Engine |
UCharacterMovementComponent | GameFramework/CharacterMovementComponent.h | Engine |
UCapsuleComponent | Components/CapsuleComponent.h | Engine |
ConstructorHelpers | UObject/ConstructorHelpers.h | CoreUObject |
UUserWidget | Blueprint/UserWidget.h | UMG |
UEnhancedInputComponent | EnhancedInputComponent.h | EnhancedInput |
UNiagaraFunctionLibrary | NiagaraFunctionLibrary.h | Niagara |
AAIController | AIController.h | AIModule |
UNavigationSystemV1 | NavigationSystem.h | NavigationSystem |
FGameplayTag | GameplayTagContainer.h | GameplayTags |
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.
- Unity builds. By default UBT merges a module’s
.cppfiles into a few large files and compiles those. An include in one file is visible to every file that comes after it in the same merged file. Adding, removing or renaming a source file changes which files are merged together, and a file that was borrowing an include loses it. - Adaptive unity. UBT uses a heuristic to detect the files you are currently working on and compiles them outside the merged files, so that iteration is faster. The side effect is that a missing include can surface on the day you start editing a file that nobody has touched for a year.
- The shared precompiled header. A game module with
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs, which is what the project templates set, is compiled against a precompiled header owned by the engine. In current UE5 it already containsEngine/Engine.h,Engine/World.h,TimerManager.hand a long list of other engine headers. That is whyGEngineworks in most game code with no include, and then fails with C2065 when the same file is built without that header, for example in a plugin compiled with strict settings or a module that sets its ownPrivatePCHHeaderFile.
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
- Build Development Editor from the IDE. The Output window should end with a line saying the build succeeded, with no
C2065,C2653orC3861above it. - Build the Development game configuration once. It catches editor-only members.
- If the code is shared with other projects or other people, do one build with unity and precompiled headers off.
- 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.
Related guides
- How to Fix “error C2027: use of undefined type” in Unreal Engine
- How to Fix “fatal error C1083: Cannot open include file” in Unreal Engine
- How to Fix “error LNK2019: unresolved external symbol” in Unreal Engine
- How to Fix “Unrecognized type - type must be a UCLASS, USTRUCT, UENUM, or global delegate” in Unreal
- How to Fix “#include found after .generated.h file” in Unreal Engine
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.