
About
Perfect Guard is a third-person combat sandbox built in Unreal Engine 5 with C++.
It's a combat systems showcase, built to answer one question that I've thought of, how does responsive, good-feeling melee combat actually work under the hood?
Inspired by Sekiro and Lies of P, it centres on a deflect-driven combat loop (parry, guard-break, dodge, punish) against enemies that make real decisions instead of running a flowchart.
Every system was built to a production standard: components over monolithic classes, data-driven configuration, and a single source of truth for every piece of state. No hardcoded values, no tangled dependencies, systems designed to be extended, not rewritten.
FULL GAMEPLAY
ARCHITECTURE
The whole project is built on five principles:
Components over monolithic classes
Every behaviour lives in its own component, HealthComponent, CombatComponent, LockOnComponent. The character owns them but doesn't implement them, so any one can be swapped without touching the rest.
A shared base, not copy-paste
Player and enemy both inherit ACombatCharacter, which owns the health component, hit-stop, and damage plumbing. Adding a new enemy type is subclass, set data, assign animations, the combat, AI, and health systems all just work because none of them know the concrete type- they only know ACombatCharacter.
Interfaces over direct dependencies
IDamageable means the weapon system never needs to know what it hit, enemy, player, or destructible. If it implements the interface, it takes damage. IGenericTeamAgentInterface drives both perception and friendly-fire from one attitude check.
Data-driven, single source of truth
Every tunable - health, damage, ranges, decision weights- lives in one authored FEnemyStats struct, applied to runtime state once at initialisation. Config seeds state; gameplay and UI only ever read state. Nothing is hardcoded, and nothing is defined in two places.
Animation-driven gameplay
Hitboxes, combo windows, i-frames, and hit-stop all fire from AnimNotifies. The animation decides when damage can happen, not a tick timer. Gameplay and animation stay in sync by construction.
COMBAT
CombatComponent
Drives the melee combo system: montage cycling, combo-window buffering, dual-sword collision via AnimNotify, and hit deduplication (TSet per swing so one swing can't multi-hit). Also owns parry, guard, and super-attack state
.h
.cpp
.cpp
HealthComponent
Manages current/max HP and broadcasts OnDamaged/OnDeath delegates, so UI, animation, and AI can react without being coupled to it. Death is handled internally, external code can't trigger it directly, only request damage.
.h
.cpp
.cpp
ACombatCharacter
The shared base for every combatant. Owns the health component, per-actor hit-stop, and the IDamageable contract. Player and enemy inherit shared behaviour and override only what genuinely differs.
.h
.cpp
AMainCharacter (Player)
The player pawn, built on ACombatCharacter and implementing IDamageable. Input handlers are thin wrappers that delegate to the combat and lock-on components, and an explicit EPlayerState machine makes illegal transitions, attacking mid-parry, moving while stunned, impossible by construction.
.h
.cpp
Deflect and Guard
A timing-gated parry with a perfect window (defined by paired AnimNotifies), guard-break mechanics, and reduced-damage guards. The core skill-expressive loop: read the attack, deflect, punish.

Player State Machine
An explicit EPlayerState machine (Idle, Moving, Attacking, Parry, Hitstun, Dodging, Dead) with centralised transition rules and cleanup. Illegal transitions are impossible, and state exits are code-owned, never left to an animation notify that might not fire.
Lock-On
Nearest-target acquisition, smoothly-interpolated camera tracking, and directional target-switching via mouse flick (read raw mouse-X, debounced to one switch per flick). Auto-retargets when a locked enemy dies; drops lock when the last one falls. All target changes funnel through one function so the on-screen indicator can never desync.

Super Attack
A cinematic multi-hit finisher that captures the target, snapping it into position and freezing its AI so every scripted hit connects, driven by a Sequencer camera and a slow-motion notify, with a code-owned restore so an interrupted finisher can never strand the world in slow-mo or leave an enemy frozen.

Directional Dodge
Input-relative dodge that selects one of four/eight directional roll animations by input angle.

ENEMY AI
Perception & Teams
Sight-based perception filtered by IGenericTeamAgentInterface, so enemies detect only hostiles. One attitude check drives both who they target and who their swings can damage, no friendly fire, no hardcoded type checks.
The Combat State Machine
The heart of the project. Rather than a tangle of behaviour-tree decorators reading five separate blackboard keys, the AI runs on a single CombatState enum as the source of truth. The controller is the brain: it reads distance bands and rolls weighted random decisions (Attack / Guard / Circle / Mid-Attack), commits to each action for its full duration, and only re-decides from a neutral "Engaged" beat. The behaviour tree becomes a dumb switch, one branch per state, mutually exclusive, impossible to get into a contradictory state.
Emergent variety
Because decisions are weighted and committed, two identical enemies fight differently in the same moment, one attacks while the other circles, with no scripting. Weights are per-enemy data, so an aggressive brute and a cautious skirmisher come from numbers, not new code.
Surround & Circle
Enemies orbit the player along a tangent (cross-product steering) and approach surround points rather than piling onto one spot, so multiple enemies engage at once instead of fighting over floor space.
Reactive Dodge
After taking punishment, enemies roll a chance to dodge out, and because it flips the same CombatState with an "abort" decorator, they can bail mid-guard or mid-swing, so it reads as the AI reacting to you, not waiting its turn.
Lifetime-safe latent tasks
Every BT task's timer uses weak-pointer guards, so a level transition or enemy death mid-action can't crash on a dangling behaviour-tree component.

GAME FEEL
Hit-stop
Per-actor time dilation on impact (attacker and victim freeze for ~70ms at 0.3 speed), so hits land with weight instead of sliding through. Per-actor rather than global, so it scales cleanly to multi-enemy fights.
Slow-motion
Authorable global slow-mo via a custom AnimNotifyState, letting animators place slow-down windows anywhere on a montage, with a mandatory code-owned restore so an interrupted montage can never leave the whole world in slow motion.

Camera Shake & Cinematics
Impact shake, FOV punch, and a Sequencer-driven finisher camera blended in and out via view targets.
VFX & Audio
Niagara blood and sword trails driven by collision notifies, and Metasound-based randomised combat audio (each swing/hit picks a random variation) so nothing sounds repetitive.


EDITOR TOOLING
Data-Driven Enemy Config
All enemy tunables live in one FEnemyStats struct, applied to the pawn at BeginPlay and read by the AI controller at possession. The pawn owns the data, the controller and tasks read it, one owner, many readers.
Enemy Config Tool (Editor Utility Widget)
A custom in-editor panel to tune enemy stats without touching Data Tables or Blueprint defaults. It reads a selected enemy's stats into the fields, edits them live, and writes them back on Apply, fully bidirectional. Crucially, it does what the Details panel can't: batch-randomize stats across a selection (instant encounter variation) and reset-to-default in one click. Built the same way a production tool is: design the clean data model first, then a thin UI over it.



CASE STUDY
Problem: With multiple enemies, only one would ever act, the others stood idle. I chased it through perception, avoidance, and acceptance radius for hours and hours, patching symptoms.
Root cause: Instrumenting it with per-enemy logging revealed the issue, the AI's "state" was smeared across five contradictory blackboard keys, and the decision logic was gated behind conditions the enemies physically couldn't reach. It wasn't a bug; it was a fragile architecture hiding its own state.
Solution: I rebuilt the whole decision system around a single CombatState enum, one source of truth, the controller as the brain, the behaviour tree as a dumb switch. The tangle of decorators became one clean condition per branch.
Result: Not only did the bug vanish, the AI became debuggable. You can now read one value and know exactly what an enemy is doing.
The lesson: good architecture doesn't just run cleaner, it makes problems visible.
The goal of this project was to learn how to build a combat character that actually feels good to control. The animation, the timing, the camera, and everything in between. It's something I've been chasing since my very first school project (a third-person ARPG), and this is the closest I've come to understanding it.
What I took away is that "good feel" isn't one thing. It's the sum of many systems, and every part has to be aligned toward that single goal before any of it clicks. Getting there meant caring about details I used to overlook.
I'm genuinely proud of what I built in four weeks. The areas that pulled me in most, and that I want to keep pushing on, are enemy AI behavior, player state machines, and editor tooling. Those are the directions I'm carrying into the next project.
