Expert guide for Unreal Engine 5.x C++ development, covering UObject hygiene, performance patterns, and best practices.
Add this skill
npx mdskills install sickn33/unreal-engine-cpp-proComprehensive UE5 C++ guide with actionable patterns, performance tips, and Epic coding standards
1---2name: unreal-engine-cpp-pro3description: Expert guide for Unreal Engine 5.x C++ development, covering UObject hygiene, performance patterns, and best practices.4risk: safe5source: self6---78# Unreal Engine C++ Pro910This skill provides expert-level guidelines for developing with Unreal Engine 5 using C++. It focuses on writing robust, performant, and standard-compliant code.1112## When to Use1314Use this skill when:15- Developing C++ code for Unreal Engine 5.x projects16- Writing Actors, Components, or UObject-derived classes17- Optimizing performance-critical code in Unreal Engine18- Debugging memory leaks or garbage collection issues19- Implementing Blueprint-exposed functionality20- Following Epic Games' coding standards and conventions21- Working with Unreal's reflection system (UCLASS, USTRUCT, UFUNCTION)22- Managing asset loading and soft references2324Do not use this skill when:25- Working with Blueprint-only projects (no C++ code)26- Developing for Unreal Engine versions prior to 5.x27- Working on non-Unreal game engines28- The task is unrelated to Unreal Engine development2930## Core Principles31321. **UObject & Garbage Collection**:33 * Always use `UPROPERTY()` for `UObject*` member variables to ensure they are tracked by the Garbage Collector (GC).34 * Use `TStrongObjectPtr<>` if you need to keep a root reference outside of a UObject graph, but prefer `addToRoot()` generally.35 * Understand the `IsValid()` check vs `nullptr`. `IsValid()` handles pending kill state safely.36372. **Unreal Reflection System**:38 * Use `UCLASS()`, `USTRUCT()`, `UENUM()`, `UFUNCTION()` to expose types to the reflection system and Blueprints.39 * Minimize `BlueprintReadWrite` when possible; prefer `BlueprintReadOnly` for state that shouldn't be trampled by logic in UI/Level BPs.40413. **Performance First**:42 * **Tick**: Disable Ticking (`bCanEverTick = false`) by default. Only enable it if absolutely necessary. Prefer timers (`GetWorldTimerManager()`) or event-driven logic.43 * **Casting**: Avoid `Cast<T>()` in hot loops. Cache references in `BeginPlay`.44 * **Structs vs Classes**: Use `F` structs for data-heavy, non-UObject types to reduce overhead.4546## Naming Conventions (Strict)4748Follow Epic Games' coding standard:4950* **Templates**: Prefix with `T` (e.g., `TArray`, `TMap`).51* **UObject**: Prefix with `U` (e.g., `UCharacterMovementComponent`).52* **AActor**: Prefix with `A` (e.g., `AMyGameMode`).53* **SWidget**: Prefix with `S` (Slate widgets).54* **Structs**: Prefix with `F` (e.g., `FVector`).55* **Enums**: Prefix with `E` (e.g., `EWeaponState`).56* **Interfaces**: Prefix with `I` (e.g., `IInteractable`).57* **Booleans**: Prefix with `b` (e.g., `bIsDead`).5859## Common Patterns6061### 1. Robust Component Lookup62Avoid `GetComponentByClass` in `Tick`. Do it in `PostInitializeComponents` or `BeginPlay`.6364```cpp65void AMyCharacter::PostInitializeComponents() {66 Super::PostInitializeComponents();67 HealthComp = FindComponentByClass<UHealthComponent>();68 check(HealthComp); // Fail hard in dev if missing69}70```7172### 2. Interface Implementation73Use interfaces to decouple systems (e.g., Interaction system).7475```cpp76// Interface call check77if (TargetActor->Implements<UInteractable>()) {78 IInteractable::Execute_OnInteract(TargetActor, this);79}80```8182### 3. Async Loading (Soft References)83Avoid hard references (`UPROPERTY(EditDefaultsOnly) TSubclassOf<AActor>`) for massive assets which force load orders. Use `TSoftClassPtr` or `TSoftObjectPtr`.8485```cpp86UPROPERTY(EditAnywhere, BlueprintReadWrite)87TSoftClassPtr<AWeapon> WeaponClassToLoad;8889void AMyCharacter::Equip() {90 if (WeaponClassToLoad.IsPending()) {91 WeaponClassToLoad.LoadSynchronous(); // Or use StreamableManager for async92 }93}94```9596## Debugging9798* **Logging**: Use `UE_LOG` with custom categories.99 ```cpp100 DEFINE_LOG_CATEGORY_STATIC(LogMyGame, Log, All);101 UE_LOG(LogMyGame, Warning, TEXT("Health is low: %f"), CurrentHealth);102 ```103* **Screen Messages**:104 ```cpp105 if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Died!"));106 ```107* **Visual Logger**: extremely useful for AI debugging. Implement `IVisualLoggerDebugSnapshotInterface`.108109## Checklist before PR110111- [ ] Does this Actor need to Tick? Can it be a Timer?112- [ ] Are all `UObject*` members wrapped in `UPROPERTY`?113- [ ] Are hard references (TSubclassOf) causing load chains? Can they be Soft Ptrs?114- [ ] Did you clean up verified delegates in `EndPlay`?115
Full transparency — inspect the skill content before installing.