An event is a message the game sends when something happens: a day passes, the player’s money changes, a door opens. Your mod subscribes to an event with a small piece of code (a handler), and the framework runs it each time that thing happens. You do not have to watch the game and check for changes yourself. This page lists every event the framework offers, grouped by the class that owns it.
When to use it
Show a message when a new day starts (Events.DayPassed).
Write to your log, or pay a bonus, when the player’s money changes (Cash.MoneyChanged).
Run set-up work once a save has loaded (Events.WhenReady, which is a method, not an event).
React when the player is fined, arrested, hurt or asleep (Law.Fined, Law.Arrested, Survival.Damaged, PlayerState.SleepStarted).
Quick example
This mod shows a notification at the start of each day, and writes every money change to its log. See Using events for a longer walk-through.
usingObenseuerCore;[ModInfo("example.eventwatcher","Event Watcher","0.1.0")][ModDependency("obenseuer.moddingframework","0.11.0")]publicsealedclassEventWatcher:FrameworkMod{protectedoverridevoidOnLoad(){Events.DayPassed+=day=>Hud.Notify("Day "+day+" has started.");Cash.MoneyChanged+=OnMoneyChanged;}privatevoidOnMoneyChanged(MoneyChangedArgsargs){Log.Info(args.Currency+": "+args.Before+" to "+args.After);}}
The += adds your handler. Most events pass one argument that describes what happened (here MoneyChangedArgs). Some pass a plain value, such as the day number, and some pass nothing.
Common tasks
Stop listening with -=, using a named method (an inline lambda has no name to remove): Cash.MoneyChanged -= OnMoneyChanged;.
Run something once a save is loaded, instead of subscribing to Events.Loaded: Events.WhenReady(() => Log.Info("save is ready"));. Events.Loaded also runs on every door change.
Find an event for a feature: look for the class of the feature in the list below (Doors, Trains, Quests and so on), then read that class’s page in the API reference for what the arguments hold.
Reference
These are all the events the framework offers, grouped by the part of the game they belong to. The optional WebUi module’s events are not listed here. The Handler type column says what your handler receives: Action<ReplantedArgs> is a method that takes one ReplantedArgs value, Action<int> takes a plain number, and Action takes nothing. The last column links to the page that explains the arguments. Most events belong to the class itself (Events.DayPassed). A few belong to one object, such as one ModSetting, and are listed last.
Raised when the quest system can be written, once per load attempt: at each save load and at each new game. A level change reloads the level without rebuilding the save and does not raise it again, while loading the same save again, another save or a new game does. Create quests here, and make the handler safe to run more than once.
Quests.Rewound
Action<QuestRewoundArgs>
Raised after the framework rewinds one of your quests: a title or description change, a restart, a reset, a removal, a jump to an objective or a checkpoint restore. Reason names the call that did it. From and To are objective keys, the first objective that was Active before the call and the first one Active after it; Remove, SetTitle and SetDescription move no objective, so both are null there and a listener must not rely on From or To for those calls.
This page is generated by tools/gen-events.py from the source. Do not edit it by hand.
Subscribe with += in OnLoad of a FrameworkMod, or in Awake of a plain BepInEx plugin.
Handlers run in the order they were added. The first throw from each handler is logged, and the other handlers still run.
The game raises events from its normal game loop. Use the framework from your handler as usual, and do not call it from a background thread you started. See main thread.