AgentSkillsCN

Cpp Coding Standards

编写UE5 C++代码,为变量、函数或类命名。

SKILL.md
--- frontmatter
description: Writing UE5 C++ code, naming variables, functions, or classes

UE5 C++ Coding Standards

Follow Epic's coding standards for Unreal Engine C++ development.

Class Prefixes

PrefixType
UUObject-derived classes
AAActor-derived classes
SSlate widget classes
FStructs and non-UObject classes
TTemplate classes
EEnum types
IInterface classes

Naming Conventions

  • PascalCase for all names (no underscores between words)
  • Boolean prefix: b (e.g., bIsActive, bDead, bCanJump)
  • U.S. English spelling in code and comments
  • No Hungarian notation except for type prefixes above

Examples

cpp
// Classes
class UHealthComponent : public UActorComponent
class ABaseCharacter : public ACharacter
class FGameStats  // Non-UObject struct

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

// Variables
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
float MaxHealth = 100.0f;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
bool bIsAlive = true;

// Functions
UFUNCTION(BlueprintCallable, Category = "Combat")
void TakeDamage(float DamageAmount);

UFUNCTION(BlueprintPure)
bool IsAlive() const;

Property Specifiers

SpecifierUse Case
EditAnywhereEditable in editor and instances
EditDefaultsOnlyEditable only in Blueprint defaults
VisibleAnywhereRead-only in editor
BlueprintReadWriteRead/write from Blueprint
BlueprintReadOnlyRead-only from Blueprint
BlueprintCallableFunction callable from Blueprint
BlueprintPurePure function (no side effects)

Best Practices

  • Use inline initialization for member variables in class declaration
  • Use forward declarations to reduce compile times
  • Add UPROPERTY/UFUNCTION macros for reflection and GC tracking

Documentation: https://dev.epicgames.com/documentation/en-us/unreal-engine/epic-cplusplus-coding-standard-for-unreal-engine