1---2name: ue5-cpp-gameplay3description: UE5.6/UE5.7 gameplay C++ implementation for Actors, Components, DataAssets, and gameplay logic. Use when requests ask to write .h/.cpp pairs, expose UPROPERTY/UFUNCTION to Blueprint, use GameplayTags, or build reusable component-based systems.4---56# Quick Start7- Confirm target class type (`AActor`, `UActorComponent`, `UObject`, `USaveGame`, etc.).8- Define required Blueprint-facing API before implementation.9- Output both header and source files together.1011# UE5.7 API Anchors12- Reflection and UObject anchors:13 - `UCLASS`, `USTRUCT`, `UENUM`, `UINTERFACE`, `GENERATED_BODY()`14 - `UPROPERTY(...)`, `UFUNCTION(...)`15- Core gameplay type anchors:16 - `AActor`, `UActorComponent`, `UDataAsset`, `UGameInstanceSubsystem`17 - `TObjectPtr<>` in headers and `TSubclassOf<>` for class references18- Replication anchors:19 - `GetLifetimeReplicatedProps(...)`20 - `DOREPLIFETIME(...)` in `Net/UnrealNetwork.h`21 - `ReplicatedUsing=OnRep_*`, `UFUNCTION(Server/Client/NetMulticast, ...)`22- Gameplay tag anchors:23 - `FGameplayTag`, `FGameplayTagContainer`24 - explicit tag request/match checks with safe fallback behavior2526# Implementation Stage Contract27- Every gameplay C++ task must define:28 - Public header API surface (Blueprint/API visibility)29 - Private runtime implementation path (`.cpp`)30 - Ownership/lifetime model (constructor, init, teardown)31 - Network authority rules (single-player only or replicated flow)32 - Validation method (compile assumptions, usage examples, edge-case behavior)33- If any item is missing, the implementation spec is incomplete.3435# Workflow36## 1) Type and File Shape37- Create type declarations with Unreal macros and UE5 pointer conventions (`TObjectPtr` in headers).38- Produce paired `.h` and `.cpp` with forward declarations in header and concrete includes in source.39- Keep class responsibility narrow and reusable.4041## 2) Public API Design42- Define Blueprint API (`BlueprintCallable`, `BlueprintPure`, categories, metadata) before implementation.43- Expose minimal callable surface; keep helper methods non-UFUNCTION unless needed.44- Declare clear input/output contracts and failure behavior.4546## 3) Runtime Implementation47- Implement logic in `.cpp` with null checks, authority guards, and explicit branch behavior.48- Keep tick usage opt-in; prefer event-driven updates.49- Handle initialization order (`BeginPlay`, `InitializeComponent`, or subsystem init) explicitly.5051## 4) Replication and RPC (When Needed)52- Add replicated properties and `OnRep_*` handlers only for true client-visible state.53- Register properties in `GetLifetimeReplicatedProps(...)` with `DOREPLIFETIME(...)`.54- Use server-authoritative RPC entry points for client requests.5556## 5) GameplayTags and Data-Driven Hooks57- Use `FGameplayTag`/`FGameplayTagContainer` with explicit tag names.58- Validate required tags at runtime and provide fallback for missing tags.59- Prefer DataAsset-driven config for tunables over hard-coded constants.6061## 6) Validation Output62- Ensure output includes both files and required includes.63- Confirm Blueprint exposure, replication behavior, and error-handling paths are documented.64- Provide usage snippet or invocation flow when behavior is non-trivial.6566# Constraints67- Always provide matching `.h` and `.cpp` when creating a class.68- Use non-deprecated APIs compatible with UE5.6/UE5.7.69- Keep includes minimal; use forward declarations in headers.70- Avoid hardcoded asset paths unless explicitly requested.71- Prefer `TObjectPtr<>` in UPROPERTY object references in headers.72- Keep server-authoritative checks explicit for any network-affecting gameplay action.7374# Failure Handling75- Symptom: class compiles but is missing from Blueprint.76 - Locate: missing `BlueprintType`/`Blueprintable`/`BlueprintCallable` metadata.77 - Fix: add required reflection specifiers and regenerate project files/build.78- Symptom: unresolved symbol or include cycles.79 - Locate: header include graph and forward declaration misuse.80 - Fix: move heavy includes to `.cpp`, keep forward declarations in headers.81- Symptom: replicated property does not update on clients.82 - Locate: `GetLifetimeReplicatedProps(...)` and actor/component replication flags.83 - Fix: register with `DOREPLIFETIME(...)`, ensure owning actor replicates.84- Symptom: `OnRep_*` never fires.85 - Locate: property write path and net role.86 - Fix: mutate on server authority path and verify property actually changes.87- Symptom: RPC callable but ignored at runtime.88 - Locate: RPC specifier and call site authority.89 - Fix: enforce client->server request path and server-side validation.90- Symptom: GameplayTag logic silently fails.91 - Locate: invalid tag names or missing tag config.92 - Fix: validate tags on startup and guard with explicit fallback behavior.9394# UE5.6 / UE5.7 Compatibility Notes95- Reflection, replication, and GameplayTag APIs above are stable across UE5.6 and UE5.7.96- Favor stable core APIs over editor-only helpers when runtime behavior is required.9798# Escalation99- Escalate when user asks for plugin/module-level refactor beyond a single gameplay class.100- Escalate when solution needs custom engine source modifications.