Spoke is a reactive framework for C# and Unity.
Inspired by React, but targeting the needs of game-logic, it's built to tame the chaos when many systems interact in dynamic, emergent ways.Spoke is a reactive framework for Unity. It turns tangled event-driven logic into clear, composable code that reads top to bottom.What problem does it solve?Games are full of long-lived behaviours, logic that starts on one frame and must be undone on a later frame:OnEnable / OnDisableAwake / OnDestroyOnEnemyDetected / OnEnemyLostSometimes they're wired up with events, sometimes with polling and diff-checking in Update(). Either way, the setup/teardown symmetry is maintained by hand, and bugs slip through. For example, an enemy is destroyed while shooting its laser beam, and the beam is left hanging in the scene because nothing cleaned it up.Spoke replaces the hand-wiring with signal-based reactivity, inspired by frontend frameworks like React and SolidJS. Game state lives in signals. Effects read signals, and re-run when they change. Before each re-run the effect cleans up after itself, so setup, reaction and cleanup live together in one block of code.Effects nest into a tree of lifetimes. The laser beam from earlier becomes: while the enemy is alive, and while it's firing, show the beam. If the enemy dies mid-beam, the beam goes with it. That's two levels of nesting, and your code stays just as clear at many more.When state changes, the affected subtree is rebuilt: stale behaviour is torn down in reverse setup order, and fresh behaviour is set up in its place.What's inside?Spoke is a toolbox of composable reactive primitives:State: a reactive value. Read it, set it, subscribe to itTrigger: a reactive event. Fire it, subscribe to itEffect / Phase / Reaction: self-cleaning blocks of logic that re-run when a value they read changesMemo: a computed value, recalculated when its inputs changeDock: attach and remove blocks dynamically, by keyHow does it fit into Unity?Subclass SpokeBehaviour instead of MonoBehaviour. Awake, OnEnable, Start, OnDisable and OnDestroy collapse into one Init blockUState is a reactive value that serializes, shows in the Inspector, and plays nice with UndoDeterministic app and scene teardown, so destruction-order exceptions stop haunting youAdopt it in one script, one system, or a whole projectHow does it perform?Spoke was born inside a VR immersive sim running on the Meta Quest. It manages lifecycles, not per-frame work, so it stays off the hot path. State updates and effect re-runs allocate zero GC; allocations only happen when new subtrees are built.It's around 2,800 lines of plain C#. No dependencies, unit-tested, MIT. The core has no Unity dependency, so it works in any C# app.The Performance doc covers this in more detail.Getting StartedRead the QuickStart guide.There's also Base Defence, a complete tower defence game written entirely in Spoke.Spoke is free and open source. You can find the GitHub repo here.FeaturesDeclarative reactivity framework for general purpose logicSupported OSAllLink to documentationIn the github repo




