MP_CombatSystem (Meme_Fight)
Technologies Used
Game Info
Gallery
Combat Director pacing and smart dodging demonstration
The combat pacing problem in action games is fundamentally a scheduling problem: which of N enemies attacks the player at any given time, and how does that decision degrade gracefully as N grows?
The standard UE approach of using a service node in a Behavior Tree to poll for attack permission scales as O(N) per tick: every enemy tree runs its service every tick regardless of whether anything changed. At 50+ enemies this creates a measurable CPU budget issue.
MP_CombatSystem solves this with a CombatDirectorComponent attached to the target (player or NPC boss). Enemies register with a specific Director on entering combat. The Director owns the token budget and distributes attack slots. Instead of enemies polling, the Director fires events when a slot opens. Enemies listen and the first to respond claims the slot via an Exclusive Registration handshake (a mutex-like push/confirm pattern) that eliminates ghost tokens from simultaneous claims.
The Behavior Tree macro layer handles target selection using a Threat Matrix: a ranked list of potential targets (player, allied NPCs, neutral actors) updated by AI Perception events. When the player dodges behind an NPC, the Threat Matrix re-evaluates and the Behavior Tree can seamlessly redirect the enemy without requiring level trigger changes.
Smart directional dodging uses cross product math to determine the enemy's position relative to incoming threats, selecting the dodge direction that maximizes distance from all attackers, with wall-avoidance raycasts preventing cornering.
Gameplay
Core Mechanics
Game Modes
Difficulty
Key Features
CombatDirectorComponent: event-driven attack token distribution replacing BT service polling
Exclusive Registration handshake protocol eliminating ghost tokens in multi-enemy claims
Dual-layer AI: Behavior Tree macro (Threat Matrix target selection) + Director micro (attack permission)
Debounced dirty-flag event system eliminating O(N^2) CPU scaling at 50+ enemies
Dynamic Threat Matrix allowing seamless Player-to-NPC target swapping mid-fight
EQS Donut positioning separated from attack phase via Wait-For-Token Decorator
Smart directional dodging via cross product spatial math with wall-avoidance raycasts
Universal HitReact system triggered by GAS Gameplay Events
Architectural Implementation
CombatDirector Token System with Exclusive Registration
Each CombatDirectorComponent maintains a token budget (max concurrent attackers). When a slot opens, it broadcasts a TokenAvailable event to all registered enemies. Interested enemies push a registration request. The Director confirms only the first valid request and rejects the rest, implementing a mutex-like handshake. This guarantees exactly N enemies attack simultaneously without race conditions, even when multiple enemies respond to the event within the same frame.
Debounced Behavior Tree Architecture
Enemy Behavior Trees use stacked Decorator gates rather than Service nodes for state evaluation. State changes (target position update, token availability) mark a dirty flag. The Decorator evaluates only when the dirty flag is set, then clears it. This means BT re-evaluation is event-driven rather than tick-driven, eliminating the constant per-frame evaluation cost of Service-based polling across large enemy groups.
EQS Donut Positioning + Wait-For-Token Separation
Enemy positioning uses an EQS Donut query to find valid melee approach positions around the target. Crucially, the EQS movement phase and the attack phase are separated by a Wait-For-Token Decorator. The enemy moves to position first, then waits for a Director token before committing to an attack. This prevents the "shameless" pattern where enemies attack immediately on reaching the target, instead producing a cinematic queued attack rhythm.
Performance Benchmarks
Zero race conditions observed in 50-enemy simultaneous combat stress tests
BT evaluation CPU cost reduced by approximately 70% vs. Service-polling baseline via debounce pattern
Exclusive Registration handshake completing within single frame at 50+ concurrent claim attempts