When prototyping an Action RPG or dungeon crawler, setting up a starting weapon with baseDamage = 100 looks like the most straightforward task in the project. We create a Weapon : MonoBehaviour or a WeaponConfigSO : ScriptableObject, assign 100 in the Inspector, and the player character swings their sword to deal damage.
However, as production scales up and game systems mature, that number 100 never remains in isolation:
- Game Designers introduce blacksmith upgrades up to level 10 (+8% base damage per level).
- Players socket elemental fire gems into the hilt (+25 flat fire damage).
- A durability system dictates that when durability reaches 0, broken weapons suffer a 50% damage penalty.
- Enemy defense mitigates incoming physical impact based on armor ratings.
- The UI tooltip needs to clearly decompose base stats, level bonuses, and active enchantments.
- The save system must persist the exact state of this weapon in player inventory without bloating the save payload.
At that point, the initial number 100 traverses multiple systems: ScriptableObject holds part of it, the inventory state holds another, the combat system applies math rules, and the UI displays floating combat text.
If the architectural boundaries between Config, Runtime Data, and Business Logic are blurred, technical debt quickly piles up: data gets embedded into logic, gameplay rules leak into config assets, and mutable runtime state corrupts shared project templates.
1. The Three Framing Questions
To establish clear architectural separation, we can categorize any value or mechanism using three guiding questions:
flowchart LR
subgraph ThreeQuestions["Three Boundary Perspectives"]
Q1["1. How is it designed?<br/>Config Layer"]
Q2["2. What is its current state?<br/>Runtime Data Layer"]
Q3["3. What rule governs the outcome?<br/>Business Logic Layer"]
end
1. Config: "How is this entity designed?"
Config defines the foundational, immutable, and shared characteristics of an object archetype:
- Weapon identifier (
WeaponId), display name, rarity tier, store purchase cost. - Base combat attributes (
baseDamage = 100), baseline critical chance, maximum durability. - Asset references: UI inventory icon, 3D character weapon prefab, swing audio clip.
These values represent the blueprint. They define the sword as a catalog item, not the specific sword currently held in a player's hands. Even if 10,000 active players equip this weapon model, they all reference this exact same blueprint. Config is owned and tuned by Game Designers, stored in ScriptableObject assets, JSON files, CSV tables, or remote configuration servers.
2. Runtime Data: "What is its current state?"
Runtime Data describes the volatile, transient condition of a specific instance at a given moment in a play session:
- What upgrade level is this specific sword? (Level 1 vs Level 8).
- How much durability remains? (82/100 or broken at 0).
- Which gem is currently socketed? (
socketedGemId = "gem_fire_tier2"). - Where is it located? (In storage chest, backpack slot 3, or equipped in the right hand).
Two weapons sharing the same IronSword config can have entirely different runtime states: one freshly looted at level 1 with pristine condition, and another upgraded to level 20, socketed with fire gems, and close to breaking. Runtime Data belongs to player ownership, changes frame-by-frame, and is the only data slice that needs serialization into save files.
3. Business Logic: "What rule governs the outcome?"
Business Logic is not data. It represents the algorithmic rules and operational constraints that dictate how Config and Runtime Data interact to produce gameplay outcomes:
- The combat resolution formula that calculates final hit points deducted from a target.
- Validation checks determining whether a player meets level and strength requirements to equip an item.
- Durability degradation rules: deducting 1 durability point on impact, and applying a 50% damage reduction when durability hits 0.
- Economy rules: gold and crafting material costs required to upgrade from level 4 to level 5.
2. Clean Architecture Data Flow
When all three layers are decoupled, data flows through the combat pipeline in a clean, unidirectional sequence:
flowchart LR
subgraph ConfigLayer["Config Layer (Immutable Blueprint)"]
SO["Weapon Blueprint<br/>BaseDamage: 100<br/>Scaling: 8% per level<br/>MaxDurability: 100"]
end
subgraph RuntimeLayer["Runtime Data (Session State)"]
RT["Player Weapon State<br/>CurrentLevel: 5<br/>CurrentDurability: 0 (Broken)<br/>ElementalBonus: +25 Fire"]
end
subgraph LogicLayer["Business Logic (Domain Rules)"]
Calc["Damage Calculator<br/>1. Scale Base by Level<br/>2. Add Elemental Buff<br/>3. Apply Broken Penalty<br/>4. Deduct Target Armor"]
end
subgraph OutputResult["Calculation Output"]
Out["Combat Calculation Result<br/>FinalDamage: 64<br/>IsBrokenPenalty: True"]
end
SO -->|"Inject base stats"| Calc
RT -->|"Inject active state"| Calc
Calc -->|"Produce output"| Out
In this pipeline:
- Config Layer provides static design constants.
- Runtime Layer provides player-owned state.
- Business Logic receives both as pure inputs, executes calculations, and outputs a result without mutating either input source.
3. Grey Areas and Nuances in Production
In real-world game development, boundaries occasionally intersect in subtle ways that require careful evaluation:
Are AnimationCurves and Growth Curves Config or Logic?
Using AnimationCurve to model stat progression across 100 levels is common in Unity:
- Keyframe positions: These are Config. Designers calibrate curve control points to shape the intended power curve.
-
Evaluation and formula application: This is Business Logic. Calling
curve.Evaluate(level)and deciding whether it multiplies base damage or adds flat bonuses is an algorithmic rule. The curve asset stays in the config, but the math logic lives in the calculation service.
Equipment Requirements
- Defining "Requires Character Level 15" is Config.
- The evaluation
player.Level >= weaponConfig.RequiredLeveland blocking the equip action is Business Logic. Embedding this check inside aScriptableObjectcreates tight coupling withPlayerCharacter, breaking config portability.
Armor Mitigation Formulas
The standard armor damage reduction formula:
$$\text{MitigatedDamage} = \text{RawDamage} \times \frac{100}{100 + \text{Armor}}$$
- The constant coefficient 100 in the denominator is Global Combat Config.
- The division and rounding logic is Business Logic. It belongs neither to the weapon nor to the enemy armor, but to the combat resolution domain service.
4. Common Architectural Anti-Patterns
When development teams lack alignment on these boundaries, projects frequently run into three structural pitfalls:
1. Business Logic Leaking into Config Assets
Adding calculation methods directly to ScriptableObject classes:
using UnityEngine;
public class PlayerCharacter : MonoBehaviour { public int Strength = 10; }
public class EnemyTarget : MonoBehaviour { public int Armor = 5; }
// Anti-Pattern: Config asset containing business logic and scene dependencies
public class FlawedWeaponConfigSO : ScriptableObject
{
public int baseDamage = 100;
public int CalculateDamage(PlayerCharacter player, EnemyTarget enemy)
{
// ScriptableObject couples directly to scene entities
int finalDamage = baseDamage + (player.Strength * 2) - enemy.Armor;
return Mathf.Max(1, finalDamage);
}
}
Consequence: The config asset becomes tightly coupled to scene GameObjects. Running headless unit tests on this formula becomes impossible without mocking full Unity scene hierarchies.
2. Runtime State Mutating Config Assets
Modifying config assets to reflect player progression:
public class UpgradeServiceAntiPattern
{
public void UpgradeWeapon(FlawedWeaponConfigSO weaponConfig)
{
// Anti-Pattern: Mutating shared asset state at runtime
weaponConfig.baseDamage += 20; // Corrupts global template for all players!
}
}
As covered previously, this mutates YAML assets on disk in the Editor, behaves inconsistently in standalone builds, and unintentionally buffs every weapon clone in the game.
3. Business Logic Scattered into UI Scripts
Duplicating formulas across presentation components:
using UnityEngine;
public class WeaponTooltipAntiPattern : MonoBehaviour
{
[SerializeField] private FlawedWeaponConfigSO _weaponConfig;
public string GetTooltipDamageText(int playerLevel)
{
// Anti-Pattern: UI component independently calculating gameplay logic
int previewDamage = _weaponConfig.baseDamage + (playerLevel * 10);
return $"Damage: {previewDamage}";
}
}
When designers alter the balance formula in the combat system, UI scripts that duplicate this calculation become out of sync, producing regression bugs where UI values diverge from combat reality.
5. Production C# Implementation: Action RPG Damage Pipeline
To illustrate clean boundary enforcement, we implement a complete weapon damage calculation pipeline for an Action RPG.
This pipeline processes a sword with a base damage of 100, handles level scaling, elemental gem bonuses, durability degradation penalties, critical hit multipliers, and enemy armor mitigation with a minimum damage floor.
1. Config Layer (Immutable Blueprint)
We define the configuration contract using an interface, implemented by a ScriptableObject:
using UnityEngine;
// Immutable configuration contract for weapon blueprints
public interface IWeaponBlueprint
{
string WeaponId { get; }
int BaseDamage { get; }
float LevelScalingFactor { get; }
int MaxDurability { get; }
}
// ScriptableObject implementation stored in Assets/Data/Weapons
public class WeaponBlueprintSO : ScriptableObject, IWeaponBlueprint
{
[SerializeField] private string _weaponId = "iron_sword";
[SerializeField] private int _baseDamage = 100;
[SerializeField] private float _levelScalingFactor = 0.08f; // +8% per level
[SerializeField] private int _maxDurability = 100;
public string WeaponId => _weaponId;
public int BaseDamage => _baseDamage;
public float LevelScalingFactor => _levelScalingFactor;
public int MaxDurability => _maxDurability;
}
2. Runtime Data Layer (Session State)
Each weapon instance in player inventory is represented by a pure C# class. It has no Unity engine dependencies and serializes cleanly into JSON save files:
using System;
// Volatile runtime state representing a concrete inventory weapon instance
[Serializable]
public class WeaponRuntimeState
{
public string InstanceGuid { get; set; }
public string BlueprintId { get; set; }
public int CurrentLevel { get; set; }
public int CurrentDurability { get; set; }
public int BonusElementalDamage { get; set; }
public WeaponRuntimeState(string instanceGuid, string blueprintId, int initialDurability)
{
InstanceGuid = instanceGuid;
BlueprintId = blueprintId;
CurrentLevel = 1;
CurrentDurability = initialDurability;
BonusElementalDamage = 0;
}
}
3. Business Logic Layer (Domain Rules)
Calculation logic is isolated inside a pure C# domain service. It has no scene references, operates purely on input parameters, and returns an immutable result struct:
using System;
// Immutable calculation result consumed by combat systems and UI
public readonly struct CombatDamageResult
{
public readonly int FinalDamage;
public readonly bool IsCritical;
public readonly bool IsBrokenPenaltyApplied;
public CombatDamageResult(int finalDamage, bool isCritical, bool isBrokenPenaltyApplied)
{
FinalDamage = finalDamage;
IsCritical = isCritical;
IsBrokenPenaltyApplied = isBrokenPenaltyApplied;
}
}
// Target defensive context
public readonly struct CombatTargetContext
{
public readonly int TargetArmor;
public readonly bool ForceCritical;
public CombatTargetContext(int targetArmor, bool forceCritical = false)
{
TargetArmor = targetArmor;
ForceCritical = forceCritical;
}
}
// Pure C# domain service executing combat calculation rules
public static class WeaponDamageCalculator
{
private const float BrokenDurabilityPenalty = 0.5f; // 50% damage reduction when broken
private const float CriticalMultiplier = 1.5f; // 1.5x damage on critical hit
private const int MinimumDamageFloor = 1; // Minimum damage is always clamped to 1
public static CombatDamageResult CalculateDamage(
IWeaponBlueprint blueprint,
WeaponRuntimeState state,
CombatTargetContext context)
{
if (blueprint == null) throw new ArgumentNullException(nameof(blueprint));
if (state == null) throw new ArgumentNullException(nameof(state));
// 1. Scale base damage by level: Base * (1 + (Level - 1) * ScalingFactor)
float levelMultiplier = 1f + ((state.CurrentLevel - 1) * blueprint.LevelScalingFactor);
float scaledBaseDamage = blueprint.BaseDamage * levelMultiplier;
// 2. Add flat elemental enchantment bonus
float rawDamage = scaledBaseDamage + state.BonusElementalDamage;
// 3. Check durability: apply penalty if weapon is broken
bool isBroken = state.CurrentDurability <= 0;
if (isBroken)
{
rawDamage *= BrokenDurabilityPenalty;
}
// 4. Apply critical hit multiplier
bool isCritical = context.ForceCritical;
if (isCritical)
{
rawDamage *= CriticalMultiplier;
}
// 5. Deduct target armor and clamp to minimum damage floor
int damageAfterArmor = (int)Math.Round(rawDamage) - context.TargetArmor;
int finalDamage = Math.Max(MinimumDamageFloor, damageAfterArmor);
return new CombatDamageResult(finalDamage, isCritical, isBroken);
}
}
4. Technical Verification via NUnit Unit Tests
Because all three layers are decoupled, we can verify our combat formulas with fast NUnit tests executing outside the Unity Editor:
using NUnit.Framework;
// Mock blueprint for isolated testing outside Unity Editor
public class MockWeaponBlueprint : IWeaponBlueprint
{
public string WeaponId { get; set; } = "iron_sword";
public int BaseDamage { get; set; } = 100;
public float LevelScalingFactor { get; set; } = 0.08f;
public int MaxDurability { get; set; } = 100;
}
[TestFixture]
public class WeaponDamageCalculatorTests
{
private MockWeaponBlueprint _blueprint;
private WeaponRuntimeState _state;
[SetUp]
public void SetUp()
{
_blueprint = new MockWeaponBlueprint();
_state = new WeaponRuntimeState("item_guid_01", _blueprint.WeaponId, _blueprint.MaxDurability);
}
[Test]
public void CalculateDamage_Level1WithDurability_DealsExpectedDamage()
{
// 100 base * 1.0 + 0 elemental = 100. Minus 20 armor = 80 damage
var context = new CombatTargetContext(targetArmor: 20, forceCritical: false);
CombatDamageResult result = WeaponDamageCalculator.CalculateDamage(_blueprint, _state, context);
Assert.AreEqual(80, result.FinalDamage);
Assert.IsFalse(result.IsCritical);
Assert.IsFalse(result.IsBrokenPenaltyApplied);
}
[Test]
public void CalculateDamage_Level5WithElementalBonus_ScalesCorrectly()
{
// Level 5: 100 * (1 + 4 * 0.08) = 132. Plus 25 fire gem = 157. Minus 15 armor = 142
_state.CurrentLevel = 5;
_state.BonusElementalDamage = 25;
var context = new CombatTargetContext(targetArmor: 15, forceCritical: false);
CombatDamageResult result = WeaponDamageCalculator.CalculateDamage(_blueprint, _state, context);
Assert.AreEqual(142, result.FinalDamage);
Assert.IsFalse(result.IsCritical);
}
[Test]
public void CalculateDamage_ZeroDurability_AppliesFiftyPercentPenalty()
{
// Level 1: 100 damage. Durability 0 -> 50% penalty = 50. Minus 10 armor = 40
_state.CurrentDurability = 0;
var context = new CombatTargetContext(targetArmor: 10, forceCritical: false);
CombatDamageResult result = WeaponDamageCalculator.CalculateDamage(_blueprint, _state, context);
Assert.AreEqual(40, result.FinalDamage);
Assert.IsTrue(result.IsBrokenPenaltyApplied);
}
[Test]
public void CalculateDamage_CriticalHit_MultipliesCorrectly()
{
// Level 1: 100 damage. Critical (1.5x) = 150. Minus 30 armor = 120
var context = new CombatTargetContext(targetArmor: 30, forceCritical: true);
CombatDamageResult result = WeaponDamageCalculator.CalculateDamage(_blueprint, _state, context);
Assert.AreEqual(120, result.FinalDamage);
Assert.IsTrue(result.IsCritical);
}
[Test]
public void CalculateDamage_ExtremelyHighArmor_ClampsToMinimumFloor()
{
// Level 1: 100 damage. Target armor is 999. Damage must be clamped to minimum floor = 1
var context = new CombatTargetContext(targetArmor: 999, forceCritical: false);
CombatDamageResult result = WeaponDamageCalculator.CalculateDamage(_blueprint, _state, context);
Assert.AreEqual(1, result.FinalDamage);
}
}
6. Layer Comparison and Trade-Offs
The following matrix summarizes the distinct responsibilities across all three architectural layers:
| Dimension | Config | Runtime Data | Business Logic |
|---|---|---|---|
| Core Nature | Static archetype blueprint | Volatile session state | Operational rules and formulas |
| Lifecycle | Persists globally across project lifetime | Persists during active session or save slot | Stateless, active during application execution |
| Storage Location | ScriptableObject, JSON, Google Sheet | Pure C# Class, SQLite, JSON Save File | Static Class, Domain Service, System |
| Ownership | Game Designer balances parameters | Player session owns instance condition | Gameplay Engineers implement and maintain rules |
| Testability | Data validation schemas | Serialization and integrity tests | Fast headless unit testing |
| Failure Mode | Asset corruption, Editor vs Build divergence | Memory leaks, bloated save files | Fragmented logic, UI divergence bugs |
7. Practical Decision Checklist
Whenever evaluating where a specific value belongs during gameplay feature development, run through this three-step checklist:
-
Does this value apply identically to every instance of this archetype?
- If Yes (Base damage, Max HP, Icon, Name) -> Place in Config.
-
Does this value mutate based on player actions during gameplay?
- If Yes (Current HP, Equipment Level, Position, Currency balance) -> Place in Runtime Data.
-
Is this value the output of an algorithm, formula, or conditional constraint?
- If Yes (Mitigated damage, drop rates modified by luck, skill unlock requirements) -> Place in Business Logic.
8. Summary
A weapon's baseDamage = 100 is intrinsically Config.
It becomes Runtime Data when tied to an upgraded or damaged weapon instance inside a player's inventory. And it flows through Business Logic when mathematical combat formulas translate it into real hit point reductions on target health bars.
Clean game architecture does not require complicated design patterns. It begins with fundamental clarity: knowing what each number in the project represents, who owns it, and where it belongs so the codebase remains stable, testable, and maintainable as the game expands.

Top comments (0)