unreal-engine-cpp-pro by sickn33/antigravity-awesome-skills
npx skills add https://github.com/sickn33/antigravity-awesome-skills --skill unreal-engine-cpp-pro本技能提供使用 C++ 进行 Unreal Engine 5 开发的专业级指导。它专注于编写健壮、高性能且符合标准的代码。
在以下情况使用此技能:
在以下情况不要使用此技能:
UObject* 成员变量,始终使用 UPROPERTY() 以确保它们被垃圾回收器跟踪。TStrongObjectPtr<>,但通常更推荐 addToRoot()。广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
IsValid() 检查与 nullptr 的区别。IsValid() 能安全地处理待销毁状态。UCLASS()、USTRUCT()、UENUM()、UFUNCTION() 将类型暴露给反射系统和蓝图。BlueprintReadWrite 的使用;对于不应被 UI/关卡蓝图中的逻辑随意修改的状态,优先使用 BlueprintReadOnly。bCanEverTick = false)。仅在绝对必要时启用。优先使用定时器(GetWorldTimerManager())或事件驱动逻辑。Cast<T>()。在 BeginPlay 中缓存引用。F 结构体以减少开销。遵循 Epic Games 的编码标准:
T(例如:TArray,TMap)。U(例如:UCharacterMovementComponent)。A(例如:AMyGameMode)。S(Slate 控件)。F(例如:FVector)。E(例如:EWeaponState)。I(例如:IInteractable)。b(例如:bIsDead)。避免在 Tick 中使用 GetComponentByClass。在 PostInitializeComponents 或 BeginPlay 中进行。
void AMyCharacter::PostInitializeComponents() {
Super::PostInitializeComponents();
HealthComp = FindComponentByClass<UHealthComponent>();
check(HealthComp); // 如果缺失,在开发环境中硬性失败
}
使用接口来解耦系统(例如,交互系统)。
// 接口调用检查
if (TargetActor->Implements<UInteractable>()) {
IInteractable::Execute_OnInteract(TargetActor, this);
}
对于强制加载顺序的大型资产,避免使用硬引用(UPROPERTY(EditDefaultsOnly) TSubclassOf<AActor>)。使用 TSoftClassPtr 或 TSoftObjectPtr。
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSoftClassPtr<AWeapon> WeaponClassToLoad;
void AMyCharacter::Equip() {
if (WeaponClassToLoad.IsPending()) {
WeaponClassToLoad.LoadSynchronous(); // 或使用 StreamableManager 进行异步加载
}
}
UE_LOG。
DEFINE_LOG_CATEGORY_STATIC(LogMyGame, Log, All);
UE_LOG(LogMyGame, Warning, TEXT("Health is low: %f"), CurrentHealth);
if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Died!"));
IVisualLoggerDebugSnapshotInterface。UObject* 成员都包装在 UPROPERTY 里了吗?EndPlay 中清理已验证的委托了吗?每周安装量
249
代码仓库
GitHub 星标数
27.1K
首次出现
Jan 29, 2026
安全审计
安装于
codex235
opencode235
gemini-cli232
github-copilot227
kimi-cli218
amp217
This skill provides expert-level guidelines for developing with Unreal Engine 5 using C++. It focuses on writing robust, performant, and standard-compliant code.
Use this skill when:
Do not use this skill when:
UObject & Garbage Collection:
UPROPERTY() for UObject* member variables to ensure they are tracked by the Garbage Collector (GC).TStrongObjectPtr<> if you need to keep a root reference outside of a UObject graph, but prefer addToRoot() generally.IsValid() check vs nullptr. IsValid() handles pending kill state safely.Unreal Reflection System :
UCLASS(), USTRUCT(), UENUM(), UFUNCTION() to expose types to the reflection system and Blueprints.BlueprintReadWrite when possible; prefer BlueprintReadOnly for state that shouldn't be trampled by logic in UI/Level BPs.Performance First :
bCanEverTick = false) by default. Only enable it if absolutely necessary. Prefer timers (GetWorldTimerManager()) or event-driven logic.Cast<T>() in hot loops. Cache references in BeginPlay.F structs for data-heavy, non-UObject types to reduce overhead.Follow Epic Games' coding standard:
T (e.g., TArray, TMap).U (e.g., UCharacterMovementComponent).A (e.g., AMyGameMode).S (Slate widgets).F (e.g., FVector).Avoid GetComponentByClass in Tick. Do it in PostInitializeComponents or BeginPlay.
void AMyCharacter::PostInitializeComponents() {
Super::PostInitializeComponents();
HealthComp = FindComponentByClass<UHealthComponent>();
check(HealthComp); // Fail hard in dev if missing
}
Use interfaces to decouple systems (e.g., Interaction system).
// Interface call check
if (TargetActor->Implements<UInteractable>()) {
IInteractable::Execute_OnInteract(TargetActor, this);
}
Avoid hard references (UPROPERTY(EditDefaultsOnly) TSubclassOf<AActor>) for massive assets which force load orders. Use TSoftClassPtr or TSoftObjectPtr.
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSoftClassPtr<AWeapon> WeaponClassToLoad;
void AMyCharacter::Equip() {
if (WeaponClassToLoad.IsPending()) {
WeaponClassToLoad.LoadSynchronous(); // Or use StreamableManager for async
}
}
Logging : Use UE_LOG with custom categories.
DEFINE_LOG_CATEGORY_STATIC(LogMyGame, Log, All);
UE_LOG(LogMyGame, Warning, TEXT("Health is low: %f"), CurrentHealth);
Screen Messages :
if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Died!"));
Visual Logger : extremely useful for AI debugging. Implement IVisualLoggerDebugSnapshotInterface.
UObject* members wrapped in UPROPERTY?EndPlay?Weekly Installs
249
Repository
GitHub Stars
27.1K
First Seen
Jan 29, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex235
opencode235
gemini-cli232
github-copilot227
kimi-cli218
amp217
Vue.js开发指南:最佳实践、组件设计与响应式编程核心原则
1,500 周安装
E (e.g., EWeaponState).I (e.g., IInteractable).b (e.g., bIsDead).