One play session
This page follows one small mod through a whole play session, from launching the game to quitting.
A tiny mod that only subscribes in OnLoad:
protected override void OnLoad()
{
Events.SceneLoaded += scene => Log.Info("scene " + scene);
Events.Loaded += () => Log.Info("loaded");
Events.Saved += () => Log.Info("saved");
Events.HourPassed += hour => Log.Info("hour " + hour);
Events.DayPassed += day => Log.Info("day " + day);
Events.WhenReady(() => Log.Info("save is ready"));
}
One session with that mod installed, in order:
-
You launch the game. Every plugin’s
Awakeruns, the framework’s first. The framework’sStartthen finds your mod, adds its component (Unity runs itsAwake), and callsOnLoad.OnLoadsubscribes to five events and queues oneWhenReadyaction. No save is loaded, soSaveData.Folderisnull. -
The main menu appears. The
Main Menuscene loads, soEvents.SceneLoadedruns with"Main Menu". The framework also clears the session here. NoLoadedruns, because nothing was loaded. -
You load a save. The scene loads first, and
Events.SceneLoadedruns while the framework is still busy, so only reads are safe there. Then the load finishes:Events.Loadedruns, then the ready point, then your queuedWhenReadyaction. That action leaves the queue as it runs, so this is its only run in the session. -
You play.
Events.HourPassedruns once for each game hour. At a day change,Events.DayPassedruns first, thenHourPassedfor the new day’s hour 0. YourUpdateruns every frame. -
You walk through a door. The game saves first, so
Events.SavedthenEvents.AfterSaverun. Then the next level loads:Events.SceneLoaded, thenEvents.Loadedagain, then the ready point. YourWhenReadyaction does not run again, because you queued it once inOnLoadand it was removed when it ran. Work you want at every door goes in yourLoadedhandler. -
You save the game.
Events.Savedruns, thenEvents.AfterSave. Nothing loads, so noLoadedand no ready point follow. -
You quit. The framework writes the settings you changed and flushes its log. Nothing else is saved, so write anything else you need before the player quits.
A new game is the exception to step 3. It does not raise Events.Loaded, because a new game does not go through the game’s save load path. The ready point still comes, at the first level of the new game, so a WhenReady action queued in OnLoad still runs. See Step 5 in Loading and playing for the same point in the full list.
Next: Starting the game.