RPG Maker-inspired Common Events, global Switches/Variables, Self-Switches, Inventory/Gold ledger, and tick-driven command scripting framework for Unity 6. It brings RPG Maker's top-to-bottom indented event scripting workflow to Unity 6 with a deterministic state-machine runner, swappable uGUI presentation components, and a UI Toolkit Event Workbench with live step debugging.
- Deterministic tick-driven state machine (
CommonEventRunner): Commands advance throughOnStart,OnTick(deltaTime), andOnCancelwith zero per-frame coroutine allocations on the runner, pause/resume support (IsPaused), single-command step debugging (StepSingleCommand), and EditMode unit testability. - RPG Maker trigger modes (
CommonEventTriggerMode):- Manual: Triggered from code (
StartEvent/StartEventById), uGUIButton.onClick(), 2D/3D trigger colliders (CommonEventTrigger), or subroutines (CallCommonEventCommandwith local call arguments andMaxCallDepthrecursion guard). - Autorun: Runs automatically in an exclusive one-at-a-time queue while its
triggerConditionsevaluate true and raisesOnControlLockChanged(bool)whenlockPlayerControlOnAutorunis enabled so character controllers or HUDs can pause input during cutscenes. - Parallel: Loops concurrently in the background while its
triggerConditionsevaluate true and cancels active commands (OnCancel) when conditions turn false.
- Manual: Triggered from code (
- Global Switches, Variables, Self-Switches, and Inventory (
WorldStateStore):- Stores named boolean Switches, typed Variables (
Int,Float,StringviaEventValue), per-object Self-Switches (A,B,C,D), non-negative Gold, and itemized Inventory counts. - Initializes default starting state from a
WorldStateDatabaseScriptableObject and exports/restores full JSON snapshots viaExportJsonandImportJson.
- Stores named boolean Switches, typed Variables (
- 29 built-in commands plus automatic custom discovery:
- Flow (11):
IfCommand,ElseCommand,EndIfCommand,LoopCommand,BreakLoopCommand,EndLoopCommand,WaitSecondsCommand,WaitUntilCommand,WaitForSignalCommand,CallCommonEventCommand,ExitEventCommand. - State & Inventory (6):
SetSwitchCommand,SetSelfSwitchCommand,SetVariableCommand(Set,Add,Subtract,Multiply,Divide,RandomIntRange),CopyVariableCommand,ModifyGoldCommand,ModifyItemCommand. - Dialogue, Screen & Audio (6):
ShowMessageCommand,ShowChoicesCommand,FadeScreenCommand,FlashScreenCommand,ShakeCameraCommand,PlayAudioCommand(PlaySfx,PlayBgm,StopBgm). - Scene & Debug (6):
EmitSignalCommand,SetObjectActiveCommand,TeleportObjectCommand,SpawnPrefabCommand,LoadSceneCommand,LogCommand. - Custom commands: Subclass
EventCommandBaseand apply[EventCommand("Category/Name")];TypeCacheregisters it in the workbench+ Add Commandmenu automatically.
- Flow (11):
- Swappable built-in presentation components:
BuiltInDialogueBox(IEventDialogueHandler) auto-builds a ScreenSpaceOverlay uGUI Dialogue and Choice Canvas usingUnityEngine.UI(LegacyRuntime.ttf, no TextMeshPro required) with configurable typewriter speed, or binds to custom uGUI references.BuiltInScreenFader(IScreenTransitionHandler) provides full-screen Fade Out/In, color Flash, and damped Camera Shake using unscaled time.BuiltInEventAudio(IEventAudioHandler) manages SFX one-shots and looping BGM through auto-created or assignedAudioSourcecomponents.
- UI Toolkit Event Workbench and scene setup menus:
- Open Tools > HaruChanZ64 > Gameplay > CommonEventsEngine > Event Workbench for an indented command editor, structural block linter, live WorldState/Inventory inspector, step-by-step debugger with an inline dialogue sandbox, and signal/binding monitor.
- Create scene rigs in one click under GameObject > CommonEventsEngine (
Create Full CommonEvents Rig,Create Dialogue Box Canvas,Create Screen Fader Canvas,Create Common Event Trigger).
- Unity
6000.0or newer com.unity.ugui(2.0.0or newer, included by default in Unity 6)
- Open Window > Package Manager in Unity 6 (
6000.0+). - Click + (top-left) and choose Install package from git URL....
- Enter:
https://github.com/haruchanz64/CommonEventsEngine.git
Add the package path to Packages/manifest.json:
{
"dependencies": {
"com.haruchanz64.common-events-engine": "file:../Plugins/CommonEventsEngine"
}
}- Create a scene rig via GameObject > CommonEventsEngine > Create Full CommonEvents Rig. This creates a
CommonEventsRigGameObject withCommonEventDirector,BuiltInDialogueBox,BuiltInScreenFader, andBuiltInEventAudiopre-wired. - (Optional) Create a starting state catalog via Assets > Create > CommonEventsEngine > World State Database and assign it to
Initial DatabaseonCommonEventDirector. - Create an event asset via Assets > Create > CommonEventsEngine > Common Event Asset.
- In the Inspector, click Open in Event Workbench (or open Tools > HaruChanZ64 > Gameplay > CommonEventsEngine > Event Workbench), then click Seed Merchant Preset to populate a complete Dialogue, Choices, Gold, Inventory, and Flash sequence.
- Switch to the 3. Live Step Debugger tab and click Start Event or Step 1 Command to run the encounter inside EditMode using the inline dialogue sandbox.
- To trigger the event in a scene, add
CommonEventTrigger(or GameObject > CommonEventsEngine > Create Common Event Trigger), assign theCommonEventAsset, and either enabletriggerOnColliderEnter, enabletriggerOnStart, or bind a uGUIButton.onClick()toCommonEventTrigger.Trigger(). - Add
CommonEventSceneBindingto scene objects (such as"Player","BossDoor", or"TownMarker") soSetObjectActiveCommand,TeleportObjectCommand, andSpawnPrefabCommandcan reference them by key without asset-to-scene links.
Each call to CommonEventRunner.Tick(deltaTime) (driven from CommonEventDirector.Update()) runs three stages unless IsPaused is true:
- Automatic trigger evaluation (
EvaluateAutomaticTriggers): ScansRegisteredEventswith non-emptytriggerConditions. EligibleAutorunevents start only when no other Autorun is active;Parallelevents start when conditions become true and cancel cleanly (OnCancel) when conditions turn false. - Process advancement (
AdvanceProcess): Only the first active Autorun process advances per tick (exclusive Autorun queue), while Manual and Parallel processes run concurrently. Each process executes up toMaxInstantCommandsPerTick(default128) instant commands per tick. Structural flow commands (IfCommand,ElseCommand,EndIfCommand,LoopCommand,BreakLoopCommand,EndLoopCommand) are resolved directly by the runner; infinite loops (maxIterations <= 0) yield one tick atEndLoopCommandto prevent main-thread freezes. - Completion and control lock (
CleanupFinishedProcesses): Removes finished processes, raisesOnEventCompleted, and updatesIsControlLocked/OnControlLockChangedwhenever an Autorun process withlockPlayerControlOnAutorunstarts or finishes.
CallCommonEventCommandpushes a newEventExecutionFrameontoActiveEventProcess.CallStackwith copied local arguments (Dictionary<string, EventValue>) and inherits the caller'sOwnerKey. Recursive calls beyondMaxCallDepth(default16) are skipped with a warning entry inrunner.Logs.CommonEventTriggerresolvesEffectiveOwnerKeyfrom itsownerKeyfield or"{sceneName}:{gameObjectName}", allowing reusableCommonEventAssetscripts (such as a treasure chest or NPC dialogue) to track independent Self-Switches (A,B,C,D) per scene object.
EmitSignal(signalName, payload)incrementsSignalSequence, appends to a 200-entry rollingSignalHistory, and raisesOnSignalEmitted.WaitForSignalCommandcapturesCurrentSignalSequenceinOnStartand resumes once a matching signal arrives with a higher sequence number, optionally storing its payload in a Global Variable.SceneBindingRegistrydecouples ScriptableObject event assets from scene hierarchy references.CommonEventSceneBindingregisters onOnEnableand unregisters onOnDisable.
Decorate any serializable subclass of EventCommandBase with [EventCommand("Category/Name", "Description")] so TypeCache lists it automatically in the Event Workbench:
using System;
using CommonEventsEngine.Core;
[Serializable]
[EventCommand("Quest/Complete Objective", "Marks a quest objective switch ON and emits a signal.")]
public sealed class CompleteObjectiveCommand : EventCommandBase
{
public string objectiveSwitch = "Quest_01_Done";
public override string GetDisplaySummary() => $"Complete Objective [{objectiveSwitch}]";
public override CommandStatus OnStart(IEventExecutionContext ctx)
{
ctx.WorldState.SetSwitch(objectiveSwitch, true);
ctx.EmitSignal("quest_objective_completed", objectiveSwitch);
return CommandStatus.Completed;
}
}Wire gameplay systems to CommonEventDirector (or directly to CommonEventRunner) to react to Autorun control locks, pass local call arguments, and persist state as JSON:
using System.Collections.Generic;
using CommonEventsEngine.Components;
using CommonEventsEngine.Core;
using CommonEventsEngine.Data;
using UnityEngine;
public sealed class CutsceneBridge : MonoBehaviour
{
[SerializeField] private CommonEventDirector director;
[SerializeField] private CommonEventAsset rewardEvent;
private string _savedSnapshot;
private void OnEnable()
{
director.Runner.OnControlLockChanged += HandleControlLock;
director.Runner.OnSignalEmitted += HandleSignal;
}
private void OnDisable()
{
if (director == null) return;
director.Runner.OnControlLockChanged -= HandleControlLock;
director.Runner.OnSignalEmitted -= HandleSignal;
}
public void GrantBonusReward(int bonusGold)
{
var args = new Dictionary<string, EventValue>
{
["BonusGold"] = EventValue.FromInt(bonusGold)
};
director.Runner.StartEvent(rewardEvent, ownerKey: "ArenaMaster", args: args);
}
public void SaveProgress() => _savedSnapshot = director.ExportSaveJson();
public void LoadProgress() => director.ImportSaveJson(_savedSnapshot);
private void HandleControlLock(bool locked) => Debug.Log($"Player control locked: {locked}");
private void HandleSignal(string signal, string payload) => Debug.Log($"Signal '{signal}': {payload}");
}Implement IEventDialogueHandler on a MonoBehaviour and assign it to Dialogue Handler Behaviour on CommonEventDirector (or assign runner.DialogueHandler in code) to replace the built-in uGUI dialogue box:
using System;
using System.Collections.Generic;
using CommonEventsEngine.Core;
using UnityEngine;
public sealed class CustomDialogueAdapter : MonoBehaviour, IEventDialogueHandler
{
public void ShowMessage(string speakerName, string message, Sprite portrait, Action onCompleted)
{
Debug.Log($"{speakerName}: {message}");
onCompleted?.Invoke();
}
public void ShowChoices(string prompt, IReadOnlyList<string> choices, int cancelChoiceIndex, Action<int> onChoiceSelected)
{
onChoiceSelected?.Invoke(0);
}
public void CancelActiveDialogue()
{
// Hide your custom dialogue UI here without invoking callbacks.
}
}| Type | Namespace | Purpose | Built-in implementation |
|---|---|---|---|
EventCommandBase |
CommonEventsEngine.Core |
Base class for [SerializeReference] commands discovered by TypeCache via [EventCommand] |
29 built-in commands in CommonEventsEngine.Commands |
IEventDialogueHandler |
CommonEventsEngine.Core |
Displays dialogue lines and selectable choice prompts | BuiltInDialogueBox (CommonEventsEngine.Presentation) |
IScreenTransitionHandler |
CommonEventsEngine.Core |
Drives screen fades, color flashes, and camera shake | BuiltInScreenFader (CommonEventsEngine.Presentation) |
IEventAudioHandler |
CommonEventsEngine.Core |
Plays one-shot SFX and looping BGM | BuiltInEventAudio (CommonEventsEngine.Presentation) |
IEventInventoryStore |
CommonEventsEngine.Core |
Stores Gold balance and item counts checked by conditions and commands | WorldStateStore (CommonEventsEngine.State) |
IEventExecutionContext |
CommonEventsEngine.Core |
Per-command runtime context exposing state, handlers, local variables, signals, and control-flow requests | Internal FrameContext inside CommonEventRunner |
CommonEventRunner |
CommonEventsEngine.Engine |
Pure C# tick-driven runner usable directly in headless simulations or EditMode tests | CommonEventRunner (hosted in scenes by CommonEventDirector) |
CommonEventAsset |
CommonEventsEngine.Data |
ScriptableObject holding trigger mode, conditions, [SerializeReference] command list, indentation, and structural validation |
CommonEventAsset |
WorldStateDatabase |
CommonEventsEngine.Data |
ScriptableObject catalog of initial Switches, Variables, starting Gold, and starting Inventory items | WorldStateDatabase |
SceneBindingRegistry |
CommonEventsEngine.State |
Maps string keys to live scene GameObject instances |
SceneBindingRegistry (populated by CommonEventSceneBinding) |
Import Custom Event Command Sample (Samples~/CustomCommands) from the Package Manager Samples tab:
SampleHealPartyCommand: customEventCommandBaseinCommonEventsEngine.Samplesdecorated with[EventCommand("RPG/Heal Party", ...)]that readsPartyHPandPartyMaxHPvariables, clamps healed HP toPartyMaxHP, and emits the"party_healed"signal with the new HP value.
The package includes EditMode NUnit tests under Tests/Editor/ runnable from Window > General > Test Runner (EditMode tab):
Tests/Editor/CommonEventsEngineTests.cs: verifies the sample Potion Merchant preset (dialogue, choices, gold deduction, inventory grant, screen flash, and insufficient-gold branch), structural block validation (ValidateStructure),Loop/BreakLoopaccumulation,WaitSecondsandWaitForSignalpayload capture, exclusiveAutoruncontrol lock (OnControlLockChanged) andParallellifecycle cancellation,CallCommonEventlocal arguments andMaxCallDepthrecursion guard, per-object Self-Switches withSceneBindingRegistryandWorldStateStoreJSON snapshot round-trip, andStepSingleCommandline-by-line execution.
- Autorun or Parallel events never start automatically:
CommonEventRunner.EvaluateAutomaticTriggers()requires at least one entry intriggerConditionsand requires the asset to be registered inCommonEventDirector'sCommon Eventslist (or viarunner.RegisterEvent). Assets with emptytriggerConditionsmust be started manually viaTriggerEvent,StartEvent, orCommonEventTrigger. - Autorun event loops infinitely after finishing: Automatic triggers are re-evaluated on every tick. If an Autorun event's trigger Switch stays
ONafter the event completes, it starts again on the next tick. Turn off the trigger Switch or update its gating Variable/Self-Switch before the event exits. - Dialogue, fade, or audio commands skip immediately: When
DialogueHandler,ScreenHandler, orAudioHandleris null,ShowMessageCommandlogs the message torunner.Logs,ShowChoicesCommandpicks choice index0, and screen/audio commands complete immediately. Attach the built-in presentation components to theCommonEventDirectorhierarchy or assign custom handlers in the Inspector. - Deactivated objects cannot be re-enabled by
SetObjectActiveCommand:CommonEventSceneBindingregisters inOnEnableand unregisters inOnDisable, so disabling a boundGameObjectremoves its key fromSceneBindingRegistry. Keep the binding on an always-active parent object or register the reference directly viaSceneBindings.Registerif you need to re-enable it later. - UI does not update after
ImportJson/ImportSaveJson:WorldStateStore.ImportJsonclears and repopulates state silently without invokingOnSwitchChanged,OnVariableChanged,OnSelfSwitchChanged,OnGoldChanged, orOnItemCountChanged. Refresh bound HUD widgets explicitly after loading a save snapshot. - Clicking Next or choice buttons on
BuiltInDialogueBoxdoes nothing:BuiltInDialogueBoxbuilds a Canvas with aGraphicRaycaster, but does not create a sceneEventSystem. Add a UnityEventSystemmatching your project's Active Input Handling, or drive dialogue from code viaAdvanceOrCompleteMessage()andSelectChoice(index). - Running the same
CommonEventAssetconcurrently: Timed and interactive commands (WaitSecondsCommand,WaitForSignalCommand,ShowMessageCommand,ShowChoicesCommand, screen transition commands) hold transient[NonSerialized]fields on the serialized command instance. Avoid launching multiple overlapping processes on the sameCommonEventAssetinstance at the same time.