<!-- skill: Unreal C++ | version: 1.0.0 | description: UCLASS gameplay abilities replication and C++ Blueprints bridge | category: Games -->
## Instructions
- Use UE 5.3+ with Live Coding disabled for shipping; compile via Rider or Visual Studio with Unreal toolchain.
- Mark every gameplay class with UCLASS / UFUNCTION / UPROPERTY specifiers; default to Blueprintable, BlueprintCallable only where needed.
- Prefer composition: AActor + UActorComponent over deep inheritance; keep tick disabled unless required.
- Introduce Gameplay Ability System with AbilitySystemComponent + GameplayEffect + GameplayTag for any RPG/combat skill.
- Replicate with DOREPLIFETIME + ReplicatedUsing=OnRep_ for state; use Server/Client/Multicast RPCs with _Validate for cheats.
- Keep Blueprints as thin presentation layer calling C++ base; never duplicate core logic in both.
- Use TSoftObjectPtr / TSoftClassPtr for async loading; avoid hard references bloating startup.
- Manage memory with UPROPERTY() pointers only; never raw new/delete for UObjects, use NewObject/SpawnActor.
- Profile with Unreal Insights + stat net; keep Server RPC size under ~1KB and frequency capped.
- Enforce const-correctness, check IsServer/HasAuthority before mutating replicated state.
- Write unit tests with Automation Spec + functional tests for abilities and replication paths.
- Document module dependencies in .Build.cs; add GameplayAbilities, GameplayTags, NetCore as needed.

## Examples
- Example 1: "health replicate" -> UPROPERTY(ReplicatedUsing=OnRep_Health) float Health; GetLifetimeReprops adds DOREPLIFETIME.
- Example 2: "fireball ability" -> UGameplayAbility subclass, CommitAbility, ApplyGameplayEffectToTarget, Montage + RPC.
- Example 3: "expose to BP" -> UFUNCTION(BlueprintCallable, Category="Combat") void TryJumpAttack(); complements unreal-blueprints skill.

## Workflows
- New class workflow: Add C++ class via editor -> add UCLASS(Blueprintable) -> compile -> create Blueprint child -> test PIE.
- GAS workflow: Add ASC to Character -> define Tags -> create Instant/Duration Effects -> create Ability -> grant via TryActivateAbility.
- Replication workflow: Mark property ReplicatedUsing -> implement OnRep -> add GetLifetimeReprops -> add Server RPC with Validate -> test 2-player PIE.
- Optimization workflow: Insights trace -> find tick offenders -> disable tick / use timers -> retest stat fps + stat net.

## Templates
- Replicated header template:
```cpp
UCLASS(Blueprintable)
class AMyChar : public ACharacter {
  GENERATED_BODY()
public:
  UPROPERTY(ReplicatedUsing=OnRep_Health, BlueprintReadOnly, Category="Stats")
  float Health = 100.f;
  UFUNCTION(Server, Reliable, WithValidation)
  void ServerTakeDamage(float Amt);
  UFUNCTION() void OnRep_Health();
  virtual void GetLifetimeReprops(TArray<FLifetimeProperty>& Out) const override;
};
```
- CPP replication:
```cpp
void AMyChar::GetLifetimeReprops(TArray<FLifetimeProperty>& Out) const {
  Super::GetLifetimeReprops(Out);
  DOREPLIFETIME(AMyChar, Health);
}
bool AMyChar::ServerTakeDamage_Validate(float A){ return A>=0 && A<500; }
void AMyChar::ServerTakeDamage_Implementation(float A){ if(HasAuthority()) Health-=A; }
```
- GAS grant checklist: [ ] ASC replicated [ ] effects data assets [ ] tags mapped [ ] ability granted on PossessedBy.

## Tools
- IDE: Rider for Unreal, Visual Studio 2022 + UnrealVS, UnrealBuildTool, Live++ (dev only).
- Engine: Unreal Insights, Gameplay Debugger, Replication Graph, Session Frontend automation.
- Plugins: GameplayAbilities, Enhanced Input, NetProfiler, Lyra sample for reference architecture.
- Build: BuildGraph, Horde CI, Perforce/Git LFS for large binaries.

## Advanced
- Use Prediction + GameplayCueManager for responsive abilities; reconcile with server correction.
- Implement custom Replication Graph nodes for 50+ actor battle royale style maps.
- Use IRangedPCG / MassEntity for crowds; avoid per-actor tick replication.
- Secure RPCs: validate ammo, cooldown, distance; log and kick on repeated invalid calls.
- Bridge pattern: C++ GameInstanceSubsystem + Blueprint UI binding via delegates, not polling.

## Documentation
- UE C++ API: https://docs.unrealengine.com/5.3/en-US/API/
- GAS docs: https://docs.unrealengine.com/5.3/en-US/gameplay-ability-system-for-unreal-engine/
- Replication: https://docs.unrealengine.com/5.3/en-US/networking-overview-for-unreal-engine/
- Lyra sample: https://docs.unrealengine.com/5.3/en-US/lyra-sample-game-in-unreal-engine/
