本文へスキップ
Skillpedia
一般的なプログラミング6.6k · #13854

unreal-cpp-gameplay

できること

Unreal Engine 5でC++のゲームプレイのコードを書き、それをエディターに接続する方法を説明します。C++でゲームのシステムを作る開発者向けです。

使う場面

  • ✓Unreal Engine 5で、C++のアクター、ポーン、キャラクター、コンポーネントを作っているとき。
  • ✓C++のプロパティや関数を、エディターやBlueprintに見せる必要があるとき。
  • ✓Build.cs ファイルで、モジュールの依存関係が不足しているとき。

スキルのリンク

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unreal/unreal-cpp-gameplay/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unreal/unreal-cpp-gameplay/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“Unrealのキャラクターのための、デザイナーがエディターで設定できるC++のヘルスコンポーネントを書いてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

スキルは、命名の接頭辞、データをエディターに公開するリフレクションのマクロ、主なフレームワークのクラスの役割、そしてモジュールの依存関係を列挙する方法を説明します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

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 with UPROPERTY/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/*.cpp using UCLASS, 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

  1. 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.
  2. 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.
  3. Expose data with UPROPERTY (editor/Blueprint visibility and garbage-collection tracking) and behaviour with UFUNCTION (BlueprintCallable, etc.).
  4. Create components in the constructor with CreateDefaultSubobject<T>(TEXT("Name")) and set the RootComponent.
  5. Know the framework roles: AGameModeBase sets the rules + default classes; APawn/ ACharacter is the controllable body; APlayerController is the player's will; UActorComponent is reusable behaviour.
  6. Add module dependencies to *.Build.cs (e.g. EnhancedInput) or unresolved-symbol link errors follow.
  7. Verify by compiling (Live Coding Ctrl+Alt+F11 from 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 with UnrealEditor-Cmd <Project>.uproject -ExecCmds="Automation RunTest MyGame;Quit" (RunTest takes a test name, a dotted prefix, or Group:<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.h not 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* without UPROPERTY — the garbage collector doesn't see it and may destroy it out from under you. Track every UObject pointer with UPROPERTY (use TObjectPtr in UE5).
  • **Header/UPROPERTY
よくある質問

リフレクションのマクロは何をしますか?

Unreal Engineにクラスとプロパティを知らせ、エディターとBlueprintからそれらが見えるようにします。

クラス名に文字の接頭辞が必要なのはなぜですか?

接頭辞は基底の型を示すもので、たとえばアクターにはAを使い、拡張する対象のクラスと一致している必要があるからです。

ビジュアルスクリプティングも扱いますか?

いいえ。Blueprintのビジュアルスクリプティングは、別のBlueprintのスキルで扱われます。

詳細

作者による元の説明

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.

repo: gamedev-skills/awesome-gamedev-agent-skills

人気

GitHubのスター
6.6k
ランキング
#13854
ライセンス
Apache-2.0
更新日
2026/10/28

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル