gamedev-skills/awesome-gamedev-agent-skills

unreal-cpp-gameplay

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.

查看源码
仓库原始内容

按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。

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.

  1. 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.

  1. Expose data with `UPROPERTY` (editor/Blueprint visibility and garbage-collection

tracking) and behaviour with UFUNCTION (BlueprintCallable, etc.).

  1. Create components in the constructor with CreateDefaultSubobject<T>(TEXT("Name")) and

set the RootComponent.

  1. 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.

  1. Add module dependencies to *.Build.cs (e.g. EnhancedInput) or unresolved-symbol

link errors follow.

  1. Verify by compiling (Live Coding Ctrl+Alt+F11 for function bodies; full rebuild for

header/UPROPERTY changes) and checking the class/properties appear in the editor.

Patterns

1. Minimal Actor class (header + source)

cpp
// 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;
};
cpp
// 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

cpp
// 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

csharp
// 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 edits with Live Coding — Live Coding handles function bodies, but

changes to UCLASS/UPROPERTY/headers need a full editor restart + rebuild.

  • Wrong class prefix — naming an Actor UFoo (or a component AFoo) breaks UHT; match the

prefix to the base type.

  • Unresolved external symbol at link — the module providing the API isn't in Build.cs

PublicDependencyModuleNames.

  • Not calling `Super::` in overridden BeginPlay/Tick/etc. skips engine setup.

References

  • For UActorComponent creation/attachment, the UPROPERTY garbage-collection ownership rules

(TObjectPtr, TArray<TObjectPtr<>>, AddToRoot), and a replication primer, read references/components-and-gc.md.

  • Primary docs: "Unreal Engine CPP Quick Start" and "Gameplay Framework"

(https://dev.epicgames.com/documentation/en-us/unreal-engine/gameplay-framework-in-unreal-engine).

Related skills

  • unreal-blueprints — exposing C++ to designers; BP/C++ interop.
  • unreal-enhanced-input — binding input in a C++ Pawn/Character.
  • unreal-behavior-trees — C++ AI tasks driven from a behaviour tree.
来自同一仓库

更多 Skills

全部 Skills
gamedev-skills
社区

game-feel

Add "juice" and game feel that makes actions satisfying — screen shake, hit-stop/freeze frames, tweened/eased motion, squash & stretch, knockback, and layered audio-visual feedback — as engine-neutral techniques that pair with the detected engine's tween, particle, and camera APIs. Use when the user mentions game feel, juice, "make it feel good/punchy", screen shake, hit stop, screen freeze, easing, squash and stretch, impact frames, or feedback/polish on hits, jumps, pickups, and deaths.

安装量
5
GitHub Stars
1113
最近更新
9月10日
gamedev-skills
社区

game-ui-ux

Design and build game UI/UX — HUDs, menus, and overlays — that survive every screen: anchor- based responsive layout, resolution/aspect scaling and safe areas, keyboard/gamepad focus navigation, a screen/menu state stack, and event-driven (not polled) HUD updates. Engine- neutral patterns that pair with the detected engine's UI skill. Use when the user mentions HUD, health bar, main menu, pause menu, settings screen, UI layout, anchors, UI scaling, aspect ratio, safe area, controller/keyboard menu navigation, or wiring UI to game state.

安装量
5
GitHub Stars
1113
最近更新
9月10日
gamedev-skills
社区

godot-3d-essentials

Set up a Godot 4.7 3D scene: Node3D transforms, Camera3D, lighting (DirectionalLight3D/OmniLight3D), WorldEnvironment for sky/ambient/tonemap/post, MeshInstance3D materials, and GridMap for tile-based 3D levels. Use when building a 3D scene in a Godot project, placing cameras/lights, configuring environment and post-processing, or working with Node3D/.tscn 3D content and GridMap.

安装量
2
GitHub Stars
1103
最近更新
9月10日
gamedev-skills
社区

godot-animation

Animate in Godot 4.7 three ways: AnimationPlayer for keyframed clips (incl. call and signal tracks), AnimationTree with state machines and blend spaces for character animation, and Tween for short procedural/UI tweens via createtween(). Use when working with AnimationPlayer/AnimationTree nodes in a .tscn, blending character states, sprite-sheet animation, or code-driven Tweens.

安装量
2
GitHub Stars
1103
最近更新
9月10日