Langsung ke konten
Skillpedia
Pemrograman umum6.6k Β· #13854

unreal-cpp-gameplay

Fungsinya

Skill ini menjelaskan cara menulis kode gameplay C++ untuk Unreal Engine 5 dan menghubungkannya ke editor. Skill ini untuk pengembang yang membangun sistem game dengan C++.

Kapan dipakai

  • βœ“Saat Anda membuat actor, pawn, character, atau component C++ di Unreal Engine 5.
  • βœ“Ketika Anda perlu menampilkan properti atau fungsi C++ di editor atau Blueprint.
  • βœ“Ketika dependensi modul hilang dari file Build.cs.

Link skill

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

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unreal/unreal-cpp-gameplay/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œTulis component kesehatan C++ untuk karakter Unreal saya yang bisa diatur desainer di editor.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Skill ini menjelaskan awalan penamaan, macro reflection yang membuka data ke editor, peran kelas-kelas framework utama, dan cara mendaftarkan dependensi modul.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum

Apa fungsi macro reflection?

Macro itu memberi tahu Unreal Engine tentang kelas dan properti Anda agar editor dan Blueprint dapat melihatnya.

Mengapa nama kelas harus memakai awalan huruf?

Awalan menunjukkan tipe dasarnya, misalnya A untuk actor, dan harus cocok dengan kelas yang diwarisinya.

Apakah ini membahas visual scripting?

Tidak. Visual scripting Blueprint dibahas dalam skill Blueprint terpisah.

Detail

Deskripsi asli dari pembuat

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

Popularitas

Bintang GitHub
6.6k
Peringkat
#13854
Lisensi
Apache-2.0
Diperbarui
28/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa