Repository navigation
Event Response System
Data-driven When / If / Then rule engine for no-code gameplay logic.
The Event Response System lets designers and modders assemble gameplay rules out of composable trigger → condition → action tuples, defined in JSON and evaluated at runtime against the live EventBus. No scripting required.
-
Header:
SparkEngine/Source/Engine/Gameplay/EventResponseSystem.h -
Impl:
SparkEngine/Source/Engine/Gameplay/EventResponseSystem.cpp(~870 LOC) -
Editor panel:
SparkEditor/Source/Panels/EventResponsePanel.{h,cpp} -
Tests:
Tests/TestEventResponseSystem.cpp(15 cases)
Every rule has the same three pieces:
WHEN [Event fires] ← EventTriggerType (OnTriggerEnter, OnDamaged, OnTimer, …)
IF [Conditions pass] ← ConditionSystem predicates
THEN [Actions execute] ← ActionType list (SpawnEntity, PlaySound, ShowUI, …)
EventResponseRule is a plain struct — name, trigger, trigger parameter, a list of conditions, and a list of actions — that serializes directly to JSON.
| Trigger | Fires on | triggerParam |
|---|---|---|
OnTriggerEnter / OnTriggerExit
|
Entity enters/exits trigger volume | — |
OnDamaged / OnKilled
|
Entity took damage / died | — |
OnItemPickup |
Item picked up | — |
OnKeyPress / OnKeyRelease
|
Input action | Action name |
OnCollision |
Physics collision | — |
OnQuestComplete |
Quest completed | — |
OnTimer |
Repeating timer | Interval in seconds |
OnStart |
Once at rule load | — |
OnWeatherChange / OnTimeOfDay
|
Weather / time-of-day changed | — |
OnEntityCreated / OnEntityDestroyed
|
Entity lifecycle | — |
OnCustom |
FireCustomEvent(name) |
Event name |
Grouped by effect:
-
Entity lifecycle —
SpawnEntity,DestroyEntity,EnableEntity,DisableEntity -
Transform —
SetPosition,MoveToward,TeleportEntity -
Audio / VFX —
PlaySound,PlayAnimation,SpawnEffect -
Gameplay state —
SetVariable,AddVariable,GiveItem,TakeItem,GiveXP -
UI / dialogue —
ShowUI,HideUI,ShowDialogue,ShowSubtitle -
Scripting bridge —
CallScript,FireCustomEvent -
Flow control —
Delay(defers remaining actions for N seconds)
Each action carries a small params array of typed values (string / int / float / bool).
Conditions reuse the ConditionSystem — the same predicate engine used by quests, abilities, and dialogue. That gives rules access to entity tags, variable comparisons, inventory checks, and quest-state checks without duplicating logic.
auto& ers = Spark::Gameplay::EventResponseSystem::GetInstance();
ers.Initialize(); // subscribes to all relevant EventBus events
// ...game loop...
ers.Update(dt); // ticks OnTimer rules and flushes delayed actions
ers.Shutdown(); // unsubscribes-
Initialize()takes a snapshot subscription to everyEventBusevent the rule engine cares about. -
Update(dt)advances timer-based rules and releases any actions queued behind aDelay. -
Shutdown()releases allSubscriptionHandleinstances so there are no dangling callbacks.
EventResponseRule rule;
rule.name = "Door Open";
rule.trigger = EventTriggerType::OnTriggerEnter;
rule.actions.push_back({ActionType::PlayAnimation, {"door_open"}});
ers.AddRule(std::move(rule));AddRule, RemoveRule, SetRuleEnabled, and ClearRules mutate the live ruleset; rules are evaluated in insertion order.
ers.FireCustomEvent("player_reached_checkpoint", playerId) fires a matched OnCustom rule. This is the extension point for gameplay systems that want to participate without adding new EventTriggerType values.
Rules round-trip to disk as JSON:
ers.SaveToJson("Content/Rules/level1.json");
ers.LoadFromJson("Content/Rules/level1.json");The JSON format mirrors the EventResponseRule fields one-to-one, which makes it friendly for external tooling and diff review.
EventResponsePanel exposes the full rule table in SparkEditor: add / remove rules, edit triggers and actions via dropdowns, enable-disable rules live, and hot-reload the JSON file. See SparkEditor for how the panel is registered.
| Use Event Response System | Use AngelScript |
|---|---|
| Designer-authored gameplay rules | Complex algorithms or state machines |
| JSON-authorable, no code review | Logic shared between client/server |
| Hot-editable in the editor | Performance-critical per-frame work |
| Fan-made mods via JSON | Full engine API access |
The two systems compose — an action can call a script, and a script can fire a custom event that triggers further rules.
- Event System — underlying EventBus that this subsystem consumes.
- Gameplay Systems — ConditionSystem, abilities, and quests all feed into conditions.
- Visual Scripting — graph-based alternative for richer logic.
- Dialogue System — can emit custom events that rules react to.
Published from 2b03dc797148. Edit the canonical source in wiki/.
- Documentation
- Docs route
- Wiki index
- Guides
- Tutorials
- Samples
- Examples
- API Reference
- API route
- Reference
- Build Guide
- Dependencies
- FAQ
- Changelog
- Roadmap
- Contributing
- Code of Conduct
- Home
- FAQ
- Getting Started
- Quick-Start Tutorial
- Making Your First Game
- Making Your First Multiplayer Game
- Artist Workflow Guide
- Editor Walkthrough
- Migration Guide
- How SparkEngine Works
- Architecture Overview
- Engine Architecture Flowchart
- Creating a Game Module
- Game Modules (catalog)
- Entity Component System
- Rendering and Graphics
- Physics
- Cloth Simulation
- Audio
- Input System
- Camera System
- Scripting with AngelScript
- Visual Scripting
- AI and Navigation
- Animation
- 2D Systems
- Networking
- Dedicated Server
- Multiplayer Quick Start
- Area Server Architecture
- Scene Management
- Large World Support
- Collaborative Editing
- Coroutine System
- Event System
- Event Response System
- Job System
- UI System
- UI Layout Extensions
- Localization
- Dialogue System
- Destruction System
- Replay System
- Achievement System
- Loading System
- Mod System
- Content Delivery
- Tween System
- Memory Integrity
- Gameplay Systems
- Terrain and Procedural Generation
- Save System
- Persistence System
- Day Night Cycle and Weather
- Cinematic Sequencer
- Runtime Prefabs
- SparkEditor
- Editor Tutorials
- SparkConsole
- SparkDaemon
- Shader Pipeline
- Asset Pipeline
- Asset Validation
- Asset Migration
- Game Packaging
- Online Services
- DataTable System
- Loot and Crafting System
- CSG System
- Font System
- Timer Manager
- Movie Render Pipeline
- HLOD and World Partition
- Remote Debug System
- Selection Manager
- Asset Dependency Graph
- Editor Automation
- File Watcher
- Project Templates
- System Requirements
- VR Support
- Mobile Platform
- Accessibility
- Platform Input
- Platform Certification
- Cross-Compilation: Wine Testing
- RHI Abstraction Layer
- D3D11 Backend
- D3D12 Backend
- Vulkan Backend
- OpenGL Backend
- Metal Backend
- DXR Raytracing
- Hybrid Ray Tracing
- Upscaling (DLSS/FSR)
- Render Graph
- Shader Graph
- GPU Particles
- GPU-Driven Rendering
- Volumetric Fog
- Volumetric Clouds
- Global Illumination
- Virtual Texturing
- Water Rendering
- Clustered Lighting
- Material System
- Post-Processing
- Shadow System
- Particle System
- Decal System
- Sky and Atmosphere
- Foliage System
- Mesh Shaders
- Neural Rendering
- Configuration Reference
- Performance Tips
- Benchmark Framework
- Threading Model
- Fuzz Policy and Parser Security
- Memory Safety
- Memory Management Patterns
- Build System and CMake Modules
- Profiler and Debugging
- Performance Profiling Guide
- Telemetry System
- Crash Reporting
- Golden Image Testing
- Utilities
- Testing
- Fuzz Policy and Parser Security
- Codebase Statistics
- Codebase Health
- Error Handling Patterns
- Hot Reload Overview
- Troubleshooting
- Contributing
- Workflow Patterns
- Build Optimizations
- CI Reproducible Builds
- GitHub API and PR Checks
- Git Rebase Conflicts
- Clang-Format
- Code Quality Violations
- AI Bloat Pattern
- MinGW + Wine Cross-Compilation
- Live Editor Testing
- Engine & Renderer Landscape
- DuetOS Portability Catalog
- Five-Engine Analysis
- Eleven-Engine Analysis
- ThorVG / Unity Graphics Analysis
- Advanced Techniques Catalog
- Third-Party Library Evaluation
- Engine Viability Evaluation
- Engine Feature Recommendations
- Project Recommendations
- Mac Compatibility Analysis
- Codebase Observations
- Codebase Bloat Audit
- Test Suite Audit
- Documentation Coverage Audit
- ThirdParty Dependencies Audit
- Load Test Baseline
- Gameplay Systems Status
- SparkGame Module Status
- Stub and Abandoned Features
- Memory Integrity System
- Memory Safety Evaluation
- Hardware Acceleration Systems
- Jolt Physics Integration
- GPU/CPU Separation Plan
- Daemon Services Architecture
- Reflection & Polymorphism Refactoring Plan
- SparkBuild In-Tree
- Wine No-JobSystem Breakthrough
- Wine Role and Fallback Tiers