Building a High-Realtime Combat System in a Game Engine: A Layered Architecture Approach
This article outlines a practical, engine-agnostic approach to building a combat system for high-realtime 3D engines. It breaks combat into five single-responsibility layers (data, rules, presentation, control, and synchronization), explains how to make balance a computable problem with pure damage formulas, and shows how frame data and state machines make combat feel responsive while remaining testable. It also covers hit detection, data-driven skills, server-authoritative multiplayer, performance tuning, and a three-tier testing loop. The architectural guidance is general and can be adapted to different technology stacks.
1. Why Combat Systems Need a Systematic Design
In high-realtime 3D engines (whose current mainstream versions follow an iterative release cadence, such as the 5.7 generation), the combat system is often the first module to bloat: as characters multiply and skills grow more complex, frame rate drops and problems erupt all at once. Many teams take a “make it playable first” approach, then pile nodes into Blueprints until they end up with a giant graph that is hard to maintain. A genuinely robust solution is to split combat into several layers, each with a single responsibility and clear interfaces, so that every layer can be tested and replaced independently.
It is worth stressing that this article is not tied to the specific interface naming of any particular commercial engine. Instead, it presents a layered approach widely accepted in the industry, along with illustrative code that is easy to port to different technology stacks.
2. Overall Layered Architecture
It is recommended to divide the combat system into five layers:
- Data layer: character base attributes, growth curves, skill configuration, and equipment affixes, all fully data-driven.
- Rules layer: damage formulas, hit/dodge, resistance mitigation, critical hits, and variance ranges.
- Presentation layer: animation, VFX, audio, and camera shake, which only consumes events and does not participate in settlement.
- Control layer: input, AI decisions, and state machine driving, which produces “intent” rather than directly changing values.
- Synchronization layer: authoritative resolution in multiplayer, plus client-side prediction and rollback.
The key principle is one-way dependency: the presentation layer depends on events, the rules layer depends on data, and the control layer only emits intent. Once the presentation layer starts modifying values in reverse, combat becomes non-reproducible.
3. Attributes and Formulas: Turning Balance into a Computable Problem
Attributes should not be scattered across character Blueprints; they should be centralized as structured configuration. Example:
// Illustrative struct, not a type specific to any enginestruct FCombatStats {float MaxHealth = 1000.f;float Attack = 120.f;float Defense = 60.f;float CritRate = 0.15f;float CritMult = 1.8f;};float ComputeDamage(const FCombatStats& A, const FCombatStats& B, float SkillScale) {float Base = A.Attack * SkillScale;float Mitigation = Base * (100.f / (100.f + B.Defense)); // Common diminishing mitigationbool bCrit = (RandomFloat() < A.CritRate);return Mitigation * (bCrit ? A.CritMult : 1.f);}
The key point is that formulas must be pure functions: the same input yields the same output (random numbers need an injectable seed). Only then can you run automated balance regression tests.
4. State Machines and Frame Data: Making Combat Feel Good and Verifiable
Combat feel comes from precise control of frame data: startup, active frames, recovery, cancel windows, and hitstun tiers. Describing this with a state machine is clearer than hardcoding it on a timeline:
- States: Idle / Move / AttackStartup / AttackActive / Recovery / Hitstun / Dead
- Transition conditions: input buffering, hit detection, being knocked back, insufficient resources
- Each state carries frame-range configuration, making it easy for designers to tune values
Combined with “input buffering + a pre-input window,” this can significantly improve combo fluidity; combined with a “cancel rules table,” it can constrain which actions can be interrupted by a dodge roll, avoiding a disconnect between numbers and feel.
5. Hit Detection: Range, Timing, and Deduplication
Hit detection commonly falls into three categories: ray casts (ranged/sniping), sweep volumes (melee swings), and area volumes (AOE). Engineering must solve three things:
- Timing alignment: synchronize active frames with animation notifies to avoid “you can see it but can’t hit it.”
- Deduplication: a single attack settles only once against the same target, tracked with an attack instance ID plus a set of target IDs.
- Priority: multi-hit detection and multi-target ordering must be stable to guarantee reproducible results.
6. Data-Driven Skills: Designers Can Change Them, Programmers Don’t Rework
Skills should be described as data assets rather than code branches: cooldown, cost, startup, hit shape, applied status, and VFX references. At runtime, a generic executor interprets the configuration, and programmers only maintain the executor and the validator. The validator checks reference integrity and value ranges before packaging, catching a large number of production incidents.
7. Multiplayer Synchronization and Anti-Cheat
The core of multiplayer combat is “authority on the server.” The client handles prediction and presentation, while the server performs the final settlement; snapshot interpolation is used for latency, and smooth rollback is used for correction to avoid teleport-like artifacts. Key values and random seeds are pushed down by the server, and the client must not decide critical hits or drops on its own.
8. Performance and Operations
As the number of characters grows, the bottleneck is usually in hit detection and animation notifies. Optimization techniques include: spreading detection across frames, spatial partitioning for culling, reusing attack instances via object pools, and LOD for VFX. On the operations side, it is recommended to integrate general cloud capabilities: use object storage to manage resource packages, use a message queue to smooth out spikes in combat logs, use a container platform to host stateless settlement services, and use logging and monitoring/alerting to locate abnormal frames and value drift. General cloud product categories from Baidu AI Cloud can serve as the underlying foundation for this kind of architecture.
9. Testing and Iteration Loop
Establish three tiers of testing: formula unit tests, state machine transition tests, and end-to-end scripted battle replays. Run a regression on every value change, outputting win-rate and duration distributions, so that balance shifts from a “feeling” to a “metric.”
