Skip to content

Game.Modding.IMod

Assembly:
Game

Namespace: Game.Modding

Type: interface

Base: None

Summary: Defines the basic lifecycle hooks for a mod. Implementers receive an UpdateSystem when the mod is loaded and are expected to perform initialization in OnLoad and cleanup in OnDispose. This interface is the entry point the game uses to initialize and tear down mod logic.


Fields

  • This interface does not declare any fields. No instance fields are defined on the interface; implementers may declare their own fields for state and references (for example, to keep a reference to the provided UpdateSystem or other services).

Properties

  • This interface does not declare any properties. If you need to expose state, add properties on your implementing class.

Constructors

  • Interfaces do not define constructors. Instantiation is done via classes that implement IMod; those classes provide their own constructors as needed by the mod loader.

Methods

  • void OnLoad(UpdateSystem updateSystem) Called when the mod is loaded by the game. The UpdateSystem instance provided is the game's update scheduler / service (API details are in its own type definition). Typical responsibilities inside OnLoad:
  • Store the provided UpdateSystem reference if you need it later.
  • Register update callbacks, event handlers or any game hooks your mod requires.
  • Initialize resources (allocate objects, read settings, create UI).
  • Avoid long-blocking operations on the main thread; use background tasks for heavy I/O and marshal results back to the main thread if needed.
  • Be prepared for exceptions to be caught/logged by the mod loader; still try to leave the game in a consistent state on failure.

  • void OnDispose() Called when the mod is being unloaded or the game is shutting down. Typical responsibilities:

  • Unregister any callbacks or event handlers you registered with UpdateSystem or other game systems.
  • Release unmanaged resources and dispose IDisposable objects.
  • Stop background tasks or ensure they can cancel cleanly.
  • Clean up any created game objects (UI, game entities) to avoid leaks or dangling references.

Usage Example

// Example implementation of IMod. Adjust Register/Unregister calls
// to match the real UpdateSystem API used in the game.

public class MyExampleMod : IMod
{
    private UpdateSystem _updateSystem;

    // Called when the mod is loaded
    public void OnLoad(UpdateSystem updateSystem)
    {
        _updateSystem = updateSystem;

        // Example: register an update callback (replace with actual API)
        // _updateSystem.Register(UpdateCallback);

        // Initialize other mod resources here (settings, UI, etc.)
    }

    // Called when the mod is unloaded
    public void OnDispose()
    {
        if (_updateSystem != null)
        {
            // Example: unregister the update callback (replace with actual API)
            // _updateSystem.Unregister(UpdateCallback);
            _updateSystem = null;
        }

        // Dispose/cleanup other resources here
    }

    // Example per-frame or periodic method
    private void UpdateCallback()
    {
        // Mod logic executed by the UpdateSystem
    }
}