unreal-cpp

A safety guide for writing Unreal Engine C++ and Blueprint code involving engine objects, memory cleanup, reflection, and frame updates.

In plain words
What is it for?
Use it when creating or changing UObject-based classes, exposing C++ to Blueprints, working with Actor updates or timers, or investigating object-lifetime crashes.
Why use it?
It helps avoid crashes from objects being collected too early, excessive Blueprint exposure, unsafe update loops, and unclear boundaries between C++ and Blueprint.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/wade-devcode/awesome-coding-skills-cn/unreal-cpp
Any agent
npx skills add Wade-DevCode/awesome-coding-skills-cn --skill unreal-cpp
Clone the repo
git clone --depth 1 https://github.com/Wade-DevCode/awesome-coding-skills-cn

Made for: Claude Code, Codex.

Per session 33 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,429 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00033 $0.02429
Opus 5 $0.00016 $0.01215
Sonnet 5 $0.00007 $0.00486
Haiku 4.5 $0.00003 $0.00243

Measured 2d ago against content hash 466560c8eadd, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

unreal-cpp scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/unreal-cpp/SKILL.md · 174 lines

How it starts

The opening of the file, as written. The whole thing — 174 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Unreal C++/蓝图

何时用

  • 新建或修改任何继承自 UObject/AActor/UActorComponent 的 C++ 类时。
  • 给蓝图暴露 C++ 函数或属性,或从 C++ 调用蓝图事件时。
  • Actor 的 Tick 频率、Timer、委托连接有疑问时。
  • 划分哪些逻辑该放 C++、哪些留给蓝图时。
  • 遇到偶发崩溃、GC 踢掉对象、野指针问题时。

核心规则

1. UObject 与 GC:UPROPERTY() 是安全绳

规则: 所有持有 UObject 派生类(Actor、Component、Asset 等)的成员变量,必须加 UPROPERTY();弱引用用 TWeakObjectPtr;原生裸指针不做持有。

为什么——真实会犯的错:.h 里写了 AEnemy* CachedEnemy; 没加 UPROPERTY(),开发期看起来没问题,进入关卡切换或 GC 整理周期后,引擎把 CachedEnemy 回收了,下一帧 CachedEnemy->TakeDamage(...) 直接崩溃。Crash log 里只有 Access violation,根本看不出是 GC 问题,排查半天。

怎么做:

  • 成员变量持有 UObject 子类 → 加 UPROPERTY()(至少空括号),让 GC 追踪引用计数。
  • 不希望阻止 GC 回收(如缓存目标但目标销毁时自动置 null)→ 用 TWeakObjectPtr<AEnemy>,使用前先 IsValid()
  • 函数局部变量、函数参数、返回值不需要 UPROPERTY(),GC 周期内不会出问题。
  • 禁止用裸指针做持有,new UObject() 也不要手动调,用 NewObject<T>()SpawnActor<T>()

2. 反射宏:按需标注,不滥标

规则: UCLASS/UFUNCTION/UPROPERTY 只在真正需要反射、蓝图互操时标注;不把所有东西都往蓝图暴露。

为什么——真实会犯的错: 把所有函数都加 BlueprintCallable、所有变量都加 EditAnywhere,编译时间膨胀,蓝图节点列表被几百个无意义函数污染,策划误用了不该在蓝图调的内部函数,出现生命周期顺序问题。另一个常见错误:忘记在 UFUNCTION() 里标 BlueprintImplementableEvent 却在 C++ 里给了函数体,导致链接错误,新手往往不知道该怎么修。

怎么做:

  • 只给蓝图调用的函数加 BlueprintCallable;只给蓝图重写的函数加 BlueprintImplementableEventBlueprintNativeEvent
  • BlueprintImplementableEvent 的 C++ 函数不能有函数体BlueprintNativeEvent 的实现写在 FuncName_Implementation 里。
  • 纯 C++ 内部函数不加任何蓝图标记,保持私有或 protected。
  • 变量只在需要编辑器/蓝图访问时才加 EditAnywhere/BlueprintReadWrite;运行时内部状态加 Transient 或不标。

3. Tick 性能:默认关,按需开

规则: Actor/Component 创建时默认设 PrimaryActorTick.bCanEverTick = false;确实需要逐帧逻辑再开,并评估能否用 Timer 或事件替代。

为什么——真实会犯的错: 场景里生成了 300 个 ABullet,每颗子弹的 Tick 里做了一次 LineTrace,帧率掉到 20 fps,Profiler 里看到几百条 ABullet::TickComponent 占满 CPU。这些子弹大多数时间都在直线飞行,根本不需要每帧 LineTrace——改成 SetActorTickInterval(0.05f) 或抛给 Projectile Movement Component 之后帧率立刻回来了。

怎么做:

  • 构造函数里 PrimaryActorTick.bCanEverTick = false 作为默认值。
  • 需要倒计时、延迟、周期回调 → 用 GetWorldTimerManager().SetTimer(),比 Tick 里减计数更清晰。
  • 需要响应状态变化 → 用 Delegate/Event,而不是 Tick 里每帧 poll。
  • 确实需要 Tick 时,用 PrimaryActorTick.TickInterval 降低频率;或在运行时 SetActorTickEnabled(false) 关掉不活跃对象的 Tick。

Read the full file on GitHub · 174 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 174 lines · 33 tokens per session scan A 466560c8eadd

Subscribe to this mod's changes

unreal-cpp is a skill published in the GitHub repository Wade-DevCode/awesome-coding-skills-cn (6 stars, last pushed 2mo ago), licensed MIT. It adds 33 tokens to every session and 2,429 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

chinese-git-workflow

国内 Git 平台配置参考——Gitee、Coding.net、极狐 GitLab、CNB 的 SSH/HTTPS/凭据/CI 接入差异与镜像同步配置。仅在用户显式 /chinese-git-workflow 时调用,不要根据上下文自动触发。.

jnMetaCode/superpowers-zh · 69 tokens

brainstorming

在任何创造性工作之前必须使用此技能——创建功能、构建组件、添加功能或修改行为。在实现之前先探索用户意图、需求和设计。.

jnMetaCode/superpowers-zh · 40 tokens

chinese-code-review

中文 review 沟通参考——话术模板、分级标注(必须修复/建议修改/仅供参考)、国内团队常见反模式应对。仅在用户显式 /chinese-code-review 时调用,不要根据上下文自动触发。.

jnMetaCode/superpowers-zh · 62 tokens

chinese-commit-conventions

中文 commit 与 changelog 配置参考——Conventional Commits 中文适配、commitlint/husky/commitizen 中文模板、conventional-changelog 中文配置。仅在用户显式 /chinese-commit-conventions 时调用,不要根据上下文自动触发。.

jnMetaCode/superpowers-zh · 65 tokens

chinese-documentation

中文文档排版参考——中英文空格、全半角标点、术语保留、链接格式、中文文案排版指北约定。仅在用户显式 /chinese-documentation 时调用,不要根据上下文自动触发。.

jnMetaCode/superpowers-zh · 62 tokens

systematic-debugging

Skill "systematic-debugging" from jnMetaCode/superpowers-zh, covering 系统化调试, 概述, 铁律, 何时使用 and 四个阶段.

jnMetaCode/superpowers-zh · 24 tokens