Skip to content

stephenvelasquez/unity-simulation-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unity-simulation-framework

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.

What's Inside

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

Core Systems

Entity Lifecycle

  • 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

Physics Pipeline

  • 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

Scenario Orchestration

  • 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

Telemetry

  • 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

Design Philosophy

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.

Quick Start

// 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();

Background

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.

License

MIT

About

Modular simulation framework for Unity — entity lifecycle, physics pipelines, scenario orchestration, and telemetry in C#.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages