unreal-cpp-gameplay
Skill này làm gì
Skill này giải thích cách viết code C++ gameplay cho Unreal Engine 5 và kết nối nó với trình soạn thảo. Nó dành cho nhà phát triển xây hệ thống game bằng C++.
Khi nào nên dùng
- ✓Khi bạn tạo một actor, pawn, character hoặc component C++ trong Unreal Engine 5.
- ✓Khi bạn cần hiển thị một thuộc tính hoặc hàm C++ trong trình soạn thảo hoặc Blueprint.
- ✓Khi thiếu phụ thuộc module trong file Build.cs.
Liên kết skill
https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unreal/unreal-cpp-gameplay/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Viết một component máu C++ cho nhân vật Unreal của tôi để nhà thiết kế có thể thiết lập nó trong trình soạn thảo.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill giải thích các tiền tố đặt tên, các macro reflection đưa dữ liệu ra trình soạn thảo, vai trò của các lớp framework chính, và cách liệt kê phụ thuộc module.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Unreal C++ Gameplay
Write correct UE5 gameplay C++: the reflection macros that connect C++ to the editor and Blueprints, the Gameplay Framework class roles, and module dependencies. Targets UE 5.8.
When to use
- Use when creating C++ gameplay classes (
AActor,APawn,ACharacter,AGameModeBase,UActorComponent), exposing properties/functions withUPROPERTY/UFUNCTION, setting up a GameMode's default classes, or adding a module dependency in*.Build.cs. - Use when the project has a
Source/tree with*.h/*.cppusingUCLASS, and*.Build.cs.
When not to use: designer-facing visual logic → unreal-blueprints. Player input
binding details → unreal-enhanced-input. AI logic → unreal-behavior-trees. This skill owns
the C++ class/reflection foundation those build on.
Core workflow
- Name with the right prefix.
A= Actor-derived,U=UObject/component-derived,F= plain struct,E= enum,I= interface. The prefix must match the base class. - Declare the class with reflection macros.
UCLASS()above the class,GENERATED_BODY()as the first line in the body, and#include "ClassName.generated.h"as the last include in the header. - Expose data with
UPROPERTY(editor/Blueprint visibility and garbage-collection tracking) and behaviour withUFUNCTION(BlueprintCallable, etc.). - Create components in the constructor with
CreateDefaultSubobject<T>(TEXT("Name"))and set theRootComponent. - Know the framework roles:
AGameModeBasesets the rules + default classes;APawn/ACharacteris the controllable body;APlayerControlleris the player's will;UActorComponentis reusable behaviour. - Add module dependencies to
*.Build.cs(e.g.EnhancedInput) or unresolved-symbol link errors follow. - Verify by compiling (Live Coding
Ctrl+Alt+F11from the editor, or a full build from the IDE with the editor closed) and checking the class/properties appear in the editor. For automation tests, run headless withUnrealEditor-Cmd <Project>.uproject -ExecCmds="Automation RunTest MyGame;Quit"(RunTesttakes a test name, a dotted prefix, orGroup:<name>).
Patterns
1. Minimal Actor class (header + source)
// Pickup.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Pickup.generated.h" // MUST be the last include
UCLASS()
class MYGAME_API APickup : public AActor // MYGAME_API = your module's export macro
{
GENERATED_BODY()
public:
APickup();
// EditAnywhere = tweak per-instance & on the CDO; BlueprintReadWrite = BP get/set.
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pickup")
int32 ScoreValue = 10;
// UPROPERTY on a UObject* pointer is what keeps it from being garbage-collected.
UPROPERTY(VisibleAnywhere)
TObjectPtr<UStaticMeshComponent> Mesh; // UE5: TObjectPtr instead of raw UStaticMeshComponent*
UFUNCTION(BlueprintCallable, Category = "Pickup")
void Collect();
protected:
virtual void BeginPlay() override;
};
// Pickup.cpp
#include "Pickup.h"
#include "Components/StaticMeshComponent.h"
APickup::APickup()
{
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
RootComponent = Mesh; // the mesh is this actor's root
}
void APickup::BeginPlay() { Super::BeginPlay(); } // always call Super
void APickup::Collect() { Destroy(); }
2. GameMode wiring its default classes
// MyGameMode.cpp — set in the constructor so the engine spawns your classes.
AMyGameMode::AMyGameMode()
{
DefaultPawnClass = AMyCharacter::StaticClass();
PlayerControllerClass = AMyPlayerController::StaticClass();
}
3. Module dependency in Build.cs
// MyGame.Build.cs
PublicDependencyModuleNames.AddRange(new string[]
{
"Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput"
});
Pitfalls
generated.hnot last / missing — compile errors like "Cannot find generated header" or "Expected an include". It must be the final include in the header.- Forgetting
GENERATED_BODY()— UHT (Unreal Header Tool) errors; it must be the first thing inside the class body. - Raw
UObject*withoutUPROPERTY— the garbage collector doesn't see it and may destroy it out from under you. Track every UObject pointer withUPROPERTY(useTObjectPtrin UE5). - **Header/UPROPERTY
Câu hỏi thường gặp
Các macro reflection làm gì?
Chúng cho Unreal Engine biết về các lớp và thuộc tính của bạn để trình soạn thảo và Blueprint nhìn thấy chúng.
Vì sao tên lớp cần một tiền tố chữ cái?
Tiền tố cho biết kiểu cơ sở, chẳng hạn A cho actor, và phải khớp với lớp mà nó kế thừa.
Skill này có bao quát kịch bản trực quan không?
Không. Kịch bản Blueprint trực quan do một skill Blueprint riêng bao quát.
Chi tiết
Mô tả gốc của tác giả
Write Unreal Engine 5 C++ gameplay code: the UCLASS/UPROPERTY/UFUNCTION reflection macros, the Gameplay Framework (GameMode, Pawn, Character, PlayerController, Actor components), and the module Build.cs. Use when writing or debugging UE C++, deriving from AActor/ACharacter/ AGameModeBase, exposing properties to the editor or Blueprints, or when the user mentions Unreal C++, UCLASS, GENERATED_BODY, GameMode, ACharacter, or .Build.cs.
Độ phổ biến
- Sao GitHub
- 6.6k
- Vị trí xếp hạng
- #13854
- Giấy phép
- Apache-2.0
- Cập nhật
- 28/10/2026
Bình luận
- …
Thêm skill từ kho mã này
router
6.6kGiúp agent của bạn chọn đúng skill phát triển game cho yêu cầu, dựa trên engine bạn dùng và loại công việc cần làm.
ai-behavior-trees-utility-ai
6.6kGiúp agent của bạn xây dựng behavior tree và hệ thống utility AI cho kẻ thù và nhân vật trong game, chọn hành động theo độ ưu tiên và điểm số.
audio-design
6.6kDạy agent cách trộn âm thanh game: bus, âm lượng theo decibel, hạ nhạc khi có thoại, nhạc thích ứng và biến thể hiệu ứng âm thanh.
camera-systems
6.6kGiúp agent của bạn xây dựng camera game bám theo mượt, giữ trong phạm vi màn chơi, và xoay quanh hoặc nhìn quanh trong 3D.
Skill tương tự
diffs
394kGiúp agent của bạn tạo một diff có thể chia sẻ về các chỉnh sửa, dưới dạng liên kết xem hoặc file ảnh, thay vì một bản tóm tắt viết tay.
coding-agent
394kGiúp agent của bạn giao một việc lập trình lớn cho Codex, Claude Code hoặc OpenCode chạy nền, rồi theo dõi tiến độ của nó.
gh-issues
394kGiúp agent của bạn tìm issue trên GitHub, chọn những issue cần xử lý và mở pull request với bản sửa, kể cả theo dõi nhận xét đánh giá.