Engineering

Systems

Technical deep-dives into gameplay engineering

architecture · trade-offs · what broke and how it got fixed

Modular Inventory System

Tools

Data-driven item management framework

MVC · ScriptableObjects

A production-ready inventory system designed with clean architecture principles. Uses ScriptableObject-based item definitions, a grid-based slot manager, and a full serialization pipeline for save/load.

C#UnityScriptableObjectsUGUIJSONEvents
Architecture deep-dive

Architecture

The system follows a Model-View-Controller pattern. The ItemRegistry holds all item definitions as ScriptableObjects. The InventoryModel manages slot state and emits events. The InventoryView listens to events and updates the UI. A SerializationLayer converts the model to/from JSON for persistence.

Challenges

  • Implementing grid-based drag-and-drop with precise collision detection
  • Designing a generic item property system without per-type code
  • Ensuring save/load integrity with item versioning

Solutions Implemented

  • Custom RectTransform overlap detection with slot snapping
  • Property bags using ScriptableObject composition
  • Schema versioning with migration callbacks

Stats

Lines: ~1,200Tests: 18 unit testsReusability: Drop-in package

BSP Dungeon Generator

Procedural

Binary Space Partitioning dungeon layout algorithm

BSP · Graph traversal

A runtime dungeon generation system using Binary Space Partitioning. Produces varied, traversable dungeons with configurable density, guaranteed connectivity, and room-type weighting for boss/treasure rooms.

C#UnityTilemap APIProcedural GenerationGraph Theory
Architecture deep-dive

Architecture

BSP tree recursively splits space into leaf nodes representing rooms. A corridor-carving pass connects sibling nodes. Room metadata is then assigned probabilistically based on tree depth. The generator outputs a TileMap-compatible grid that Unity's Tilemap API populates.

Challenges

  • Guaranteeing all rooms are reachable without backtracking
  • Balancing randomness vs. playable level design
  • Integrating enemy spawning with room context

Solutions Implemented

  • Minimum spanning tree pass over room graph ensures connectivity
  • Configurable depth and split-ratio constraints keep layouts playable
  • Room type tagging drives spawn tables at level load time

Stats

Lines: ~800Performance: <2ms per genMaps: ∞ unique layouts

Universal Save System

Tools

Flexible, type-safe game state serialization

SLOT 1 — ActiveSLOT 2 — EmptySLOT 3 — Empty
{ "v": 2, "enc": true }
AES · JSON.NET

A flexible save system supporting multiple save slots, auto-save, and type-safe serialization. Components register themselves as saveable via an interface, decoupling persistence logic from gameplay code.

C#UnityJSON.NETAES EncryptionInterfaces
Architecture deep-dive

Architecture

SaveableObjects implement ISaveable and register with the SaveManager on Awake. On save, the manager collects JSON blobs from all registered objects and writes them to an encrypted file per slot. On load, each object receives its own data blob and deserializes independently.

Challenges

  • Avoiding tight coupling between save logic and game objects
  • Handling save data migration between game versions
  • Performance on large scene counts

Solutions Implemented

  • ISaveable interface + SceneContext dependency injection
  • Version field + migration strategy pattern
  • Async write pipeline with background thread offload

Stats

Lines: ~600Slots: UnlimitedOverhead: <0.5ms

Hierarchical Enemy AI

AI

Layered behavior tree with utility scoring

Selector
PatrolCombatRetreatAttackFlank
BT · NavMesh · Utility

A hierarchical AI system combining behavior trees for decision logic with utility scoring for target prioritization. Enemies exhibit patrol, detection, combat, flanking, and retreat behaviors that adapt based on health and squad context.

C#UnityNavMeshBehavior TreesUtility AI
Architecture deep-dive

Architecture

A lightweight behavior tree evaluates each tick: Selector/Sequence/Leaf nodes compose complex behavior. A utility layer weights candidate actions (attack, flank, retreat, call-for-help) using normalized sensor inputs. A steering layer handles movement using Unity's NavMesh with obstacle avoidance layering.

Challenges

  • Preventing repetitive predictable enemy patterns
  • Coordinating group behavior without expensive global queries
  • Tuning utility weights without hand-tweaking every enemy type

Solutions Implemented

  • Noise-injected utility scores add controlled unpredictability
  • Squad blackboard shared via object reference, no global lookup
  • Parameterized utility curves on ScriptableObject profiles

Stats

Lines: ~2,000Enemies: 50+ simultaneousCost: <0.8ms at 30 enemies

Modular Ability System

Gameplay

Runtime-composable gameplay ability framework

DMGAOESFXVFXCD
Composition · ScriptableObj

A data-driven ability system where abilities are composed from atomic Effect modules at runtime. Supports cooldowns, resource costs, targeting modes, visual feedback hooks, and runtime upgrades without code changes.

C#UnityScriptableObjectsComposition PatternVFX Graph
Architecture deep-dive

Architecture

AbilityDefinition ScriptableObjects hold arrays of AbilityEffect assets. At cast time, a composite executor chains effects in sequence/parallel. Targeting modes (projectile, AOE, raycast, melee) are swappable strategy objects. A visual feedback system subscribes to ability lifecycle events to drive VFX and audio.

Challenges

  • Designing effects general enough to compose meaningfully
  • Handling targeting across different camera perspectives
  • Keeping ability logic testable without a running game

Solutions Implemented

  • Atomic effects: Damage, Move, Spawn, Apply Status, Trigger Event
  • Camera-agnostic targeting resolvers injected at runtime
  • Effect units are pure C# classes, tested independently from MonoBehaviour

Stats

Lines: ~1,500Abilities: Infinite by compositionEffects: 12 atomic types

Netcode Prediction Layer

Multiplayer

Client-side prediction with server reconciliation

CLIENT
Input[]
SERVER
State
Ring Buffer — 16 framesPrediction · Rollback · NGO

A netcode abstraction layer implementing client-side prediction, authoritative server state, and rollback/reconciliation. Designed as a wrapper around Unity Netcode for GameObjects to simplify deterministic gameplay code.

C#UnityNGOMultiplayerRing BufferRollback
Architecture deep-dive

Architecture

Each frame, the client records input into a circular buffer and simulates locally. The server processes inputs authoritatively and broadcasts state snapshots. The client compares its predicted state against server snapshots and rolls back + re-simulates if divergence exceeds a threshold.

Challenges

  • Achieving visual smoothness during reconciliation corrections
  • Keeping the rollback buffer memory-bounded
  • Handling physics interactions deterministically

Solutions Implemented

  • Visual interpolation layer decoupled from simulation layer
  • Fixed-size ring buffer with configurable history depth
  • Physics inputs serialized and replayed, not physics state

Stats

Lines: ~1,800Latency masked: Up to 150msPlayers tested: 2-8