-
-
Notifications
You must be signed in to change notification settings - Fork 2
Game events
English | 日本語
Experimental. This came in with core 1.2.0 (framework 1.2.0).
GameEvents lives in the core (DragNWash.ModFramework). The framework receives the game's events once and hands them to each mod separately. If a handler throws, it's logged and shown on the Mods screen under its mod, and the other mods' handlers still run.
If a handler on SceneManager.sceneLoaded throws, it stops every mod that subscribed after it, and nobody can tell which mod it was. That's exactly what the framework's first principle is there to prevent, so GUIDE rule 9 asks mods to take these events from GameEvents instead.
private void Awake()
{
GameEvents.OnSceneLoaded(MyMod.Guid, (scene, mode) => ApplyTo(scene));
GameEvents.OnGameStarted(MyMod.Guid, () => Log("The title screen is up."));
GameEvents.OnQuitting(MyMod.Guid, SaveMyState);
}
private void OnDestroy() => GameEvents.Remove(MyMod.Guid);| Member | What it does |
|---|---|
void OnSceneLoaded(string ownerGuid, Action<Scene, LoadSceneMode> handler) |
After every scene load |
void OnSceneUnloaded(string ownerGuid, Action<Scene> handler) |
After every scene unload |
void OnGameStarted(string ownerGuid, Action handler) |
Once, when the title screen is first shown and the game's systems exist. A handler added after that runs straight away |
void OnQuitting(string ownerGuid, Action handler) |
When the game is quitting |
bool IsGameStarted |
True once the title screen has been shown |
void Remove(string ownerGuid) |
Takes out every handler that mod registered |
- The exception goes to the log with the mod's GUID and the event's name, and the Mods screen shows the failure under that mod (the same way
GameHooks.Unavailableshows a missing game member). - The other mods' handlers for the same event still run.
- A handler that fails three times in a row is switched off for the session. One success resets the count.
- A handler that takes longer than 100 ms is noted in the debug log, so you can trace a slow scene load back to a mod.
That's on purpose. A MonoBehaviour's Update is the right tool for per-frame work. A framework-wide Update would put every mod's frame work in one place, and then one slow mod would slow everyone down.
Players
Mod authors
- Getting started
- Playing well with others (the guide)
- Going online
- Installer
- Mod reload
- Overrides (no code)
- Graphs (no code, makes things happen)
Tools (F1, developer tools)
- Inspector
- Console
- Code graph
- Bridge (AI clients, MCP)
API
日本語
- ホーム
- プレイヤー向け · ランチャー · FAQ · クラッシュレポート
- はじめての Mod · ほかの Mod と一緒に動かす · 外と通信する Mod · インストーラー · Mod の再読み込み · Overrides · Graphs
- Inspector · Console · コードのグラフ · Bridge
- 中核 API · 操作の登録簿 · Text · Dialogue · Tool window · Assets · Flags and saves · GameEvents · SettingMeta
Links
- Repository
- Releases
- Changelog
- Design records: DESIGN · ROADMAP · CONTENT_POLICY