Ue Gameplay Framework 标志

Ue Gameplay Framework

社区
kevinpbuckley
ue-gameplay-framework

Implement Unreal's gameplay framework in C++ — GameInstance, AGameModeBase/AGameMode, AGameStateBase/AGameState, APlayerController, APawn/ACharacter, APlayerState, and AHUD — including the server-only spawn/login flow, possession, controller-pawn lifecycle, and which class each piece of logic belongs in. Use when setting up game rules, default pawn/controller classes, player login/spawn/possession, replicated game or player state, match-state machines, respawn logic, or deciding "where does this code live?"

概览

发布者kevinpbuckley
代码仓库unreal-engine-skills
技能名称ue-gameplay-framework
星标数
89
复刻数
9
附带文件
3
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 3 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 kevinpbuckley 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Ue Gameplay Framework AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/kevinpbuckley/unreal-engine-skills/tree/master/skills/core/ue-gameplay-framework
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/kevinpbuckley/unreal-engine-skills.git /tmp/unreal-engine-skills
mkdir -p .claude/skills
cp -r /tmp/unreal-engine-skills/skills/core/ue-gameplay-framework .claude/skills/ue-gameplay-framework
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Ue Gameplay Framework,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Ue Gameplay Framework。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Ue Gameplay Framework 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Gameplay framework

The gameplay framework is the set of base classes Unreal spawns and wires together to run a game. Choosing the right class for each piece of logic is the single most important design decision in UE gameplay code.

When to use this skill

  • Creating a new game mode, game state, player controller, pawn, player state, or HUD class.
  • Implementing player login, spawn, respawn, or possession logic.
  • Deciding where a piece of state lives (server-only vs replicated vs per-player vs cross-level).
  • Setting up default classes in C++ and exposing them to designers via Blueprint subclasses.
  • Wiring the spawn/possession flow or implementing a match-state machine.

The classes and their roles

ClassLives whereCore responsibilityReplicated?
UGameInstanceone per game, persists across level loadsapp-lifetime state, subsystems, online sessionsno
AGameModeBaseserver onlyrules, default classes, login/spawn flowno
AGameModeserver onlyadds match-state machine on top of Baseno
AGameStateBaseserver + all clientsgame-wide visible state (score, timer, match phase)yes
AGameStateserver + all clientsadds MatchState replication to Baseyes
APlayerControllerserver + owning clientinput, camera, UI, possession bridgeto owner only
APlayerStateserver + all clientsper-player replicated data (name, score, team)yes
APawnserver + clientsphysical avatar in the worldyes
ACharacterserver + clientsbipedal pawn with movement, capsule, skeletal meshyes
AHUDowning client onlylegacy canvas overlay (prefer UMG for real UI)local

Class hierarchy (verified in 5.8 source):

  • AGameModeBase : public AInfo (GameModeBase.h:47); AGameMode : public AGameModeBase (GameMode.h:35).
  • AGameStateBase : public AInfo (GameStateBase.h:32); AGameState : public AGameStateBase (GameState.h:16).
  • APlayerController : public AController (PlayerController.h:262); AController : public AActor (Controller.h:40).
  • APawn : public AActor (Pawn.h:43); ACharacter : public APawn (Character.h:338).
  • APlayerState : public AInfo (PlayerState.h:41); AHUD : public AActor (HUD.h:36).
  • UGameInstance : public UObject, public FExec (Engine/GameInstance.h:151).

Base vs non-base: AGameModeBase and AGameStateBase are the lean modern defaults. AGameMode/AGameState add the match-state machine (MatchState, WaitingToStart, InProgress, WaitingPostMatch, …) inherited from UE3-era multiplayer. Start from *Base unless you need match states.

Ownership and relationship map

UGameInstance (persists across levels)
└── UWorld (current level)
    ├── AGameModeBase       (server only — rules and spawning)
    ├── AGameStateBase      (replicated — global visible state)
    │   └── PlayerArray: TArray<APlayerState*>   (one per connected player, replicated)
    └── per player:
        APlayerController ──possesses──> APawn / ACharacter
              │                              └── movement, mesh, collision components
              └── PlayerState  (also in GameState.PlayerArray)

Key accessors verified in 5.8 source:

  • GetWorld()->GetGameState<T>() — replicated on all machines.
  • GetWorld()->GetAuthGameMode<T>() — server only; returns null on clients.
  • GetGameInstance<T>() — available via any UObject with a valid outer chain.
  • AController::GetPawn() (Controller.h:233); APawn::GetController() (Pawn.h:264).
  • APawn::GetPlayerState<T>() (Pawn.h:193); AController::PlayerState (Controller.h:50).

Server spawn and login flow

On the server, AGameModeBase drives the sequence when a player joins:

  1. InitGame (GameModeBase.h:62) — called before any actor PreInitializeComponents; spawn helper classes here.
  2. PreLogin (GameModeBase.h:293) — reject players by setting ErrorMessage before any state is allocated.
  3. Login (GameModeBase.h:323) — creates and returns the APlayerController; spawns APlayerState.
  4. PostLogin(PC) (GameModeBase.h:326) — first safe place to call replicated functions on the PC.
  5. HandleStartingNewPlayer(PC) (GameModeBase.h:361) — override in Blueprint or C++ to control what happens next.
  6. RestartPlayer(PC) (GameModeBase.h:435) → FindPlayerStart → SpawnDefaultPawnAtTransform → PC->Possess(Pawn).

Full login flow with seamless travel and OnPostLogin details: references/init-and-login-flow.md.

Possession

AController::Possess(APawn*) is final in 5.8; override OnPossess instead (Controller.h:299). The symmetric unpossess override is OnUnPossess (Controller.h:306).

cpp
// Override OnPossess to react to possession — NOT Possess() which is final
void AMyController::OnPossess(APawn* InPawn)
{
    Super::OnPossess(InPawn);
    // Safe to access InPawn here; PlayerState is already assigned
}

// On the pawn side, PossessedBy fires when a controller takes control
void AMyPawn::PossessedBy(AController* NewController)
{
    Super::PossessedBy(NewController);
    // Bind abilities, movement, etc. that depend on the controller
}

A controller can possess different pawns over its lifetime (death/respawn, vehicle enter/exit). Do not store gameplay state on the pawn that must survive across possessions — use PlayerState or PlayerController instead.

Setting default classes in C++

cpp
// MyGameMode.h
UCLASS()
class MYGAME_API AMyGameMode : public AGameModeBase
{
    GENERATED_BODY()
public:
    AMyGameMode();
};

// MyGameMode.cpp
#include "MyGameMode.h"
#include "MyCharacter.h"
#include "MyPlayerController.h"
#include "MyPlayerState.h"
#include "MyGameState.h"

AMyGameMode::AMyGameMode()
{
    DefaultPawnClass       = AMyCharacter::StaticClass();
    PlayerControllerClass  = AMyPlayerController::StaticClass();
    PlayerStateClass       = AMyPlayerState::StaticClass();
    GameStateClass         = AMyGameState::StaticClass();
    // HUDClass — set if you use legacy AHUD; omit for pure UMG
}

These five TSubclassOf<> properties are declared on AGameModeBase with EditAnywhere, NoClear, BlueprintReadOnly (GameModeBase.h:87–108). Assign them in the constructor so Blueprint subclasses can still override them in Blueprints editor defaults.

Then wire the GameMode per-project (Project Settings → Maps & Modes → DefaultGameMode/GlobalDefaultGameMode in DefaultEngine.ini [/Script/EngineSettings.GameMapsSettings]), or per-level (World Settings → GameMode Override).

Where does my logic go? (decision guide)

LogicBelongs in
Rules, win/lose, who spawns where, scoring authorityAGameModeBase — server only
State everyone must see (scores, timer, match phase)AGameStateBase / AGameState
Per-player replicated facts (name, team, kills)APlayerState
Input handling, camera, opening menus, player intentAPlayerController
Physical movement, abilities of the avatarAPawn / ACharacter + components
Cross-level or app-lifetime (save game, audio settings, online session)UGameInstance / a UGameInstanceSubsystem

If it must survive a level load → UGameInstance or UGameInstanceSubsystem (see ue-subsystems). If only the server may decide it → AGameModeBase.

GameInstance and subsystems

UGameInstance is created once on engine launch and destroyed when the application exits, surviving all level transitions. Override Init (GameInstance.h:217) and Shutdown (GameInstance.h:224) for setup/teardown. Access it from any actor via GetGameInstance<UMyGameInstance>().

For modular, dependency-isolated systems with the same lifetime:

cpp
// Subsystem declared as UCLASS(), auto-created by GameInstance
class UMyOnlineSubsystem : public UGameInstanceSubsystem
{
    GENERATED_BODY()
public:
    virtual void Initialize(FSubsystemCollectionBase& Collection) override;
    virtual void Deinitialize() override;
};

// Access from any actor
UMyOnlineSubsystem* Sub = GetGameInstance()->GetSubsystem<UMyOnlineSubsystem>();

GetSubsystem<T>() is declared on UGameInstance (GameInstance.h:440). See ue-subsystems.

PlayerState — per-player replicated data

APlayerState is created by Login and added to AGameStateBase::PlayerArray. It replicates to all clients, making it the correct place for data every machine needs about each player.

cpp
// MyPlayerState.h
UCLASS()
class MYGAME_API AMyPlayerState : public APlayerState
{
    GENERATED_BODY()
public:
    UPROPERTY(Replicated, BlueprintReadOnly, Category=Player)
    int32 TeamIndex = 0;

    virtual void GetLifetimeReplicatedProps(
        TArray<FLifetimeProperty>& OutLifetimeProps) const override;
};

Built-in replicated fields on APlayerState: Score (getter GetScore, setter SetScore, PlayerState.h:312/318), PlayerNamePrivate (accessed via GetPlayerName/SetPlayerName, PlayerState.h:235/228), PlayerId, CompressedPing, bIsSpectator, bIsABot.

Network roles

  • AGameModeBase exists only on the server; never put client logic there.
  • AGameStateBase/APlayerState are replicated — read on any machine, only write on server.
  • APlayerController replicates to its owning client only — good for client RPCs and UI.
  • APawn/ACharacter replicate to all clients; HasAuthority() determines who may change state.
  • Use HasAuthority() or GetLocalRole() == ROLE_Authority to branch server vs client.

See ue-networking-and-replication for property/RPC mechanics.

C++ base + Blueprint subclass pattern

The idiomatic setup:

  • Put logic, replicated state, and core API in C++ (AMyGameMode, AMyCharacter, …).
  • Expose designer-facing defaults via Blueprint subclasses (BP_GameMode, BP_Character, …).
  • Set the BP subclasses as defaults in Project Settings or World Settings.
  • Use UPROPERTY(EditDefaultsOnly) for numbers/assets designers should tweak without requiring recompile. See ue-blueprint-cpp-integration.

Gotchas

  • GetAuthGameMode() on a client returns null; always guard with HasAuthority().
  • Possess is final since UE 4.22; override OnPossess/OnUnPossess (Controller.h:299/306).
  • Persistent state on the Pawn is lost on death/respawn; use APlayerState or APlayerController.
  • Possession ≠ spawn: a controller can possess different pawns over time; don't assume 1:1 lifetime.
  • AGameMode vs AGameModeBase mismatch: MatchState machinery only exists in AGameMode; don't reference it from an AGameModeBase subclass.
  • DispatchPostLogin deprecated in 5.6: override OnPostLogin(AController*) instead (GameModeBase.h:334 — note the UE_DEPRECATED annotation at :329).
  • HUD for modern UI: AHUD is legacy canvas drawing; build real UI with UMG (see ue-umg-and-slate).
  • APlayerState outlives the pawn: the state persists in GameState.PlayerArray even when the pawn is destroyed; that is by design so scores survive death.
  • GameInstance is not replicated: the server and each client each have their own independent instance. Do not use it as a shared-state store in multiplayer.

Version notes

  • AGameModeBase introduced in UE 4.14; older projects may subclass AGameMode directly.
  • Possess/UnPossess marked virtual final in UE 4.22; use OnPossess/OnUnPossess.
  • DispatchPostLogin deprecated in UE 5.6; the replacement is OnPostLogin (protected virtual).
  • The framework is stable across UE 5.x; line numbers in citations drift between patch releases but header paths and class names are stable.

References & source material

Engine source (UE 5.8, under Engine/Source/Runtime/Engine/Classes/):

  • GameFramework/GameModeBase.h — AGameModeBase:47, InitGame:62, InitGameState:69, DefaultPawnClass:108, PlayerControllerClass:96, PlayerStateClass:100, GameStateClass:92, HUDClass:104, PreLogin:293, Login:323, PostLogin:326, OnPostLogin:334, HandleStartingNewPlayer:361, RestartPlayer:435, SpawnDefaultPawnAtTransform:461, ChoosePlayerStart:405, GetDefaultPawnClassForController:84.
  • GameFramework/GameMode.h — AGameMode:35, MatchState namespace:16, GetMatchState:43, StartMatch:51, EndMatch:55, SetMatchState:72.
  • GameFramework/GameStateBase.h — AGameStateBase:32, PlayerArray:55, GetServerWorldTimeSeconds:72, HasBegunPlay:76, AddPlayerState:112, RemovePlayerState:115.
  • GameFramework/GameState.h — AGameState:16, MatchState:35, ElapsedTime:57.
  • GameFramework/Controller.h — AController:40, PlayerState:50, GetPawn():233, Possess (final):284, UnPossess (final):288, OnPossess:299, OnUnPossess:306.
  • GameFramework/PlayerController.h — APlayerController:262, PlayerCameraManager:287, MyHUD:280, SetInputMode:1649, SetShowMouseCursor:2168.
  • GameFramework/Pawn.h — APawn:43, GetController():264, GetPlayerState<T>():193, PossessedBy:374, UnPossessed:381.
  • GameFramework/Character.h — ACharacter:338.
  • GameFramework/PlayerState.h — APlayerState:41, Score:49, GetScore:312, SetScore:318, PlayerNamePrivate:162, GetPlayerName:235, SetPlayerName:228.
  • GameFramework/HUD.h — AHUD:36, PlayerOwner:42, bShowHUD:50.
  • Engine/GameInstance.h — UGameInstance:151, Init:217, Shutdown:224, GetSubsystem<T>():440.

Official docs (UE 5.8, all fetched and confirmed live):

Deep-dive references in this skill:

Cross-references: ue-actors-and-components (AActor lifecycle), ue-character-and-movement (ACharacter / UCharacterMovementComponent detail), ue-subsystems (UGameInstanceSubsystem), ue-networking-and-replication (replication mechanics), ue-blueprint-cpp-integration (exposing C++ to designers).

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Ue Gameplay Framework AI 技能有什么作用?

Implement Unreal's gameplay framework in C++ — GameInstance, AGameModeBase/AGameMode, AGameStateBase/AGameState, APlayerController, APawn/ACharacter, APlayerState, and AHUD — including the server-only spawn/login flow, possession, controller-pawn lifecycle, and which class each piece of logic belongs in. Use when setting up game rules, default pawn/controller classes, player login/spawn/possession, replicated game or player state, match-state machines, respawn logic, or deciding "where does this code live?"

为什么在 TypingMind 中使用 Ue Gameplay Framework?

因为您只需安装一次,就能搭配任何模型使用。Ue Gameplay Framework 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Ue Gameplay Framework?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/kevinpbuckley/unreal-engine-skills/tree/master/skills/core/ue-gameplay-framework。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Ue Gameplay Framework?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Ue Gameplay Framework 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Ue Gameplay Framework 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Ue Gameplay Framework AI 技能免费吗?

kevinpbuckley 已在 GitHub 上发布了该技能。请查看代码仓库了解许可条款。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇