unreal-cpp-architecture
БесплатноБез исполняемых скриптовНе проверенUse when writing Unreal Engine 5 C++ - the gameplay framework classes and where logic belongs, UObject/AActor/UActorComponent lifecycle, UPROPERTY/UFUNCTION…
от makifbaysal★ 123 звезды на GitHubОб этом скилле
Unreal C++ Architecture
Overview
Unreal gives you a full gameplay framework, a reflection system and a garbage collector. Most bugs in Unreal C++ come from fighting them: raw UObject* members the GC frees underneath you, gameplay logic in constructors that only ever run on the class default object, logic on the wrong framework class (GameMode code running on clients), and everything ticking every frame.
Core principle: Put each piece of logic on the framework class that owns it, keep every UObject reference visible to the GC, and let C++ own systems while Blueprints own content and tuning.
Where logic belongs
| Class | Lives on | Owns |
|---|---|---|
AGameModeBase |
Server only | Rules of the match: spawning, scoring rules, win conditions |
AGameStateBase |
Server + replicated to all | Match state everyone sees (time left, team scores) |
APlayerController |
Owning client + server | Input routing, UI ownership, camera for that player |
APlayerState |
Replicated to all | Per-player persistent data (name, score); survives pawn death |
APawn / ACharacter |
Replicated | The body: movement, the components that act in the world |
UActorComponent |
With its actor | Reusable behaviour (health, inventory, interaction) |
UGameInstanceSubsystem / UWorldSubsystem / ULocalPlayerSubsystem |
Process / world / local player | Services (save, matchmaking, spawning registries) — instead of singletons |
A client asking GetWorld()->GetAuthGameMode() gets nullptr — that is the design, not a bug to work around.
Lifecycle
AHeroCharacter::AHeroCharacter() {
// Constructor: defaults and subobjects only. It runs for the class default object too,
// so no world access, no spawning, no gameplay.
PrimaryActorTick.bCanEverTick = false;
Health = CreateDefaultSubobject<UHealthComponent>(TEXT("Health"));
}
void AHeroCharacter::BeginPlay() {
Super::BeginPlay(); // always call Super
Health->OnDied.AddDynamic(this, &AHeroCharacter::HandleDied);
}
void AHeroCharacter::EndPlay(const EEndPlayReason::Type Reason) {
GetWorldTimerManager().ClearAllTimersForObject(this);
Super::EndPlay(Reason);
}
Order to remember: constructor → PostInitializeComponents → BeginPlay → Tick → EndPlay. Components: InitializeComponent (if bWantsInitializeComponent) → BeginPlay.
Reflection and the garbage collector
UCLASS()
class UInventoryComponent : public UActorComponent {
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "Inventory")
bool TryAdd(const UItemDefinition* Item, int32 Count);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnInventoryChanged, const UInventoryComponent*, Inventory);
UPROPERTY(BlueprintAssignable) FOnInventoryChanged OnChanged;
private:
// ❌ UItemDefinition* Cached; invisible to the GC: freed under you, then a crash
// ✅ visible to the GC, editor-tunable, null-safe
UPROPERTY(EditDefaultsOnly, Category = "Inventory", meta = (ClampMin = "1"))
int32 SlotCount = 20;
UPROPERTY(Transient) TArray<FInventorySlot> Slots;
UPROPERTY() TObjectPtr<const UItemDefinition> LastAdded;
TWeakObjectPtr<AActor> LastInteractor; // non-owning: check IsValid() before use
};
- Every
UObject*member is aUPROPERTY(TObjectPtr<T>for members in UE5), aTWeakObjectPtr, or aTStrongObjectPtr(from non-UObject code). Raw pointers only as locals and parameters. - Create objects with
NewObject<T>(Outer),CreateDefaultSubobject(constructor only) orGetWorld()->SpawnActor— nevernew. IsValid(Ptr)before using anything that may have been destroyed (IsValidalso catches "pending kill").EditDefaultsOnlyfor tuning on the Blueprint class,EditAnywhereonly when level instances should differ,VisibleAnywherefor components.
The C++ / Blueprint boundary
- C++: systems, rules, replication, anything performance-sensitive or tested.
- Blueprints: content (which mesh, which sound, which montage), tuning values, level scripting, and composition of C++ components.
- Expose a small surface:
BlueprintCallablefor actions,BlueprintPurefor queries,BlueprintImplementableEvent/BlueprintNativeEventfor designer hooks. No gameplay rule that exists only in a Blueprint graph nobody can test. - Blueprints reference heavy assets through soft references (
TSoftObjectPtr) so loading one class does not pull the whole content graph (game-asset-pipeline).
Enhanced Input
void AHeroController::BeginPlay() {
Super::BeginPlay();
if (auto* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer())) {
Subsystem->AddMappingContext(DefaultContext, /*Priority*/ 0);
}
}
void AHeroCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
auto* Input = CastChecked<UEnhancedInputComponent>(PlayerInputComponen
Установить unreal-cpp-architecture в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл unreal-cpp-architecture?
Use when writing Unreal Engine 5 C++ - the gameplay framework classes and where logic belongs, UObject/AActor/UActorComponent lifecycle, UPROPERTY/UFUNCTION and GC-safe pointers (TObjectPtr, TWeakObjectPtr), subsystems, the C++/Blueprint boundary, Enhanced Input, tick discipline, and compiling from the command line.
Как установить скилл unreal-cpp-architecture?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл unreal-cpp-architecture запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic