Loading
These notes cover when your mod starts, and what happens when it fails or stops.
Things to know
- The framework loads every framework mod in one go, after all BepInEx plugins have started. Do your starting work in
OnLoad. (BepInEx plugins have all runAwakeby then.) OnLoadruns once.Loader.Has(yourOwnId)isfalsewhile your mod’s ownAwakeandOnLoadare running, and becomestruewhenOnLoadfinishes.-
Unity runs your class’s own
AwakebeforeOnLoad. A framework mod stays loaded until the game closes. (Mono cannot unload an assembly.) FrameworkMods.Loaded()gives a new list of the framework mods that loaded. A mod that failed inOnLoadis not in it. UseLoader.Has(modId)to ask about one mod by its id.
Limits
- If
OnLoadthrows an error, your mod is switched off. The error goes to your mod’s log and toObenseuerCore.log, and your mod’s component is destroyed straight away, so itsUpdatecannot run on a half-started mod. Every mod that depends on yours is skipped, but other mods and the framework keep running. - Things your mod did before the error are not undone, such as event subscriptions, saved-data registrations and game patches. Register them last in
OnLoad. - An error in your class’s
Awakeis logged by Unity, and the framework does not stop it from spreading.