Modular simulation framework for Unity — entity lifecycle management, configurable physics pipelines, scenario orchestration, and telemetry. Built for teams that use game engines to solve problems beyond games: training simulations, digital twins, and mixed-reality experiences.
Written in C# because Unity is C#, and because the patterns here (ECS-adjacent, event-driven, inspector-friendly) only make sense inside the Unity runtime.
unity-simulation-framework/
├── Runtime/
│ ├── Core/
│ │ ├── SimulationManager.cs # Top-level orchestrator
│ │ ├── EntityRegistry.cs # Entity lifecycle and lookup
│ │ ├── EventBus.cs # Decoupled publish/subscribe
│ │ └── TimeController.cs # Simulation clock (pause, scale, step)
│ ├── Physics/
│ │ ├── PhysicsPipeline.cs # Configurable physics step pipeline
│ │ ├── CollisionResolver.cs # Collision detection and response
│ │ └── ForceAccumulator.cs # Force composition and application
│ ├── Scenario/
│ │ ├── ScenarioRunner.cs # Scenario lifecycle (load, run, evaluate)
│ │ ├── ScenarioConfig.cs # Scriptable Object scenario definitions
│ │ └── ObjectiveEvaluator.cs # Success/failure criteria evaluation
│ ├── Telemetry/
│ │ ├── TelemetryCollector.cs # Metric collection during simulation
│ │ ├── TelemetryExporter.cs # Export to JSON/CSV for analysis
│ │ └── PerformanceProfiler.cs # Frame time, GC, memory tracking
│ └── Editor/
│ ├── SimulationInspector.cs # Custom inspector for SimulationManager
│ └── ScenarioEditorWindow.cs # Editor window for scenario authoring
├── Tests/
│ ├── EntityRegistryTests.cs
│ ├── EventBusTests.cs
│ └── PhysicsPipelineTests.cs
├── package.json # Unity Package Manager manifest
└── unity-simulation-framework.asmdef # Assembly definition
- Registry pattern — centralized entity creation, lookup, and destruction
- Component-based — entities are compositions of behaviors, not inheritance trees
- Pooling-ready — entity recycling for high-frequency spawn/despawn scenarios
- Event-driven — entity state changes broadcast via EventBus
- Configurable steps — add/remove/reorder physics stages without touching core loop
- Force accumulation — multiple force sources compose cleanly (gravity, thrust, drag, control surfaces)
- Deterministic mode — fixed timestep with state hashing for replay and validation
- ScriptableObject configs — designers author scenarios without code
- Objective system — composable success/failure criteria with AND/OR logic
- Phased execution — scenarios progress through setup → run → evaluate → teardown
- Batch mode — run thousands of scenarios headless for parameter sweeps
- Zero-allocation collection — no GC pressure during simulation
- Structured export — JSON and CSV for downstream analysis in Python/R
- Live profiling — frame time, physics step cost, memory, GC in editor overlay
This framework exists because Unity is increasingly used for serious applications — not just games. Training simulators for defense, digital twins for manufacturing, mixed-reality experiences for healthcare. These applications need the same rigor as backend systems: testable, observable, deterministic.
The architecture is deliberately not a full ECS rewrite. It works with Unity's existing GameObject/MonoBehaviour model while providing the structure that large simulation projects need. Think of it as the missing "simulation middleware" layer.
// Create a simulation
var sim = SimulationManager.Instance;
sim.Initialize(scenarioConfig);
// Register entities
var entity = sim.Registry.Spawn(prefab, position, rotation);
// Subscribe to events
sim.EventBus.Subscribe<CollisionEvent>(OnCollision);
// Run
sim.TimeController.Play();Built from patterns developed while working with Unity at Microsoft, where game engine technology is applied to simulation, mixed reality, and training scenarios. The framework reflects lessons learned shipping products where "game-quality" means "mission-critical" — deterministic physics, observable state, and testable scenarios are non-negotiable.
MIT