Mother DocsMother Docs
Buy me a Coffee
Steam Workshop
Discord
  • Mother OS (Ingame Script)
Buy me a Coffee
Steam Workshop
Discord
  • Mother OS (Ingame Script)
  • Mother OS (Ingame Script)
    • Getting Started

      • Upgrade Guide
      • Installation
      • Command Line Interface (CLI)
      • Configuration
      • Modules
    • Core Modules

      • Activity Monitor
      • Almanac
      • Block Catalogue
      • Local Storage
      • Intergrid Message Service
    • Extension Modules

      • Air Vent Module
      • Battery Module
      • Terminal Block Module
      • Cockpit Module
      • Connector Module
      • Display Module
      • Docking Module
      • Door Module
      • Flight Control Module
      • Flight Planning Module
      • Gas Tank Module
      • Gyroscope Module
      • Hinge Module
      • Landing Gear Module
      • Light Module
      • Map Module
      • Piston Module
      • Programmable Block Module
      • Rotor Module
      • Screen Module
      • Sensor Module
      • Sorter Module
      • Sound Block Module
      • Thruster Module
      • Timer Block Module
    • Command Cheatsheet
    • Compatibility
    • Examples
  • Mother Core (Script Framework)
    • Getting Started

      • Upgrade Guide
      • Installation
      • Architecture Overview
      • Managing Script Size & Complexity
    • Building A Module
    • Console (CLI)
    • Core Modules
      • Activity Monitor
      • Almanac
      • Block Catalogue
      • Clock
      • Command Bus
      • Configuration
      • Event Bus
      • Intergrid Message Service
      • Local Storage
      • Terminal
    • Utilities

      • Color Helper
      • Security
      • Serializer
  • Powered By Mother

Event Bus

The Event Bus is uses to manage event subscriptions and ensure events are emitted to the correct modules.

  • Subscribing to an Event
  • Emitting an Event
  • Listening for an Event
  • Unsubscribing from an Event

Subscribing to an Event

Before we can take action when an event is emitted, we need to subscribe to it. This is typically done in the Boot() method of an extension module.

MissileGuidanceModule.cs
// show code to subscribe to an event from within an extension module with the boot method
public class MissileGuidanceModule : BaseExtensionModule
{
    // show code to emit an event from within an extension module
    public override void Boot()
    {
        // subscribe using the Event Bus module
        Mother.GetModule<EventBus>().Subscribe<MissileLaunchedEvent>(this);

        // Or via a helper method
        Subscribe<MissileLaunchedEvent>();
    }
}

Emitting an Event

We can emit an event by using the Emit() method. Any module that has subscribe to this event will receive it.

MissileGuidanceModule.cs
// show code to emit an event from within an extension module
public void Launch()
{
    // Do launch stuff
    // ...

    Mother.GetModule<EventBus>().Emit(new MissileLaunchedEvent());
}

Since this is a very common activity, the BaseExtensionModule class provides an accessor method:

MissileGuidanceModule.cs
public class MissileGuidanceModule : BaseExtensionModule
{
    public void Launch()
    {
        // Do launch stuff
        // ...
        Emit<MissileLaunchedEvent>();
    }
}

Listening for an Event

Extension modules can override the HandleEvent() method to listen for events to which they have subscribed. This method will be called whenever an event is emitted to this module.

MissileGuidanceModule.cs
public class MissileGuidanceModule : BaseExtensionModule
{
    // Handle the event
    public override void HandleEvent(IEvent e, object eventData)
    {
        if (e is MissileLaunchedEvent)
            ArmWarhead();
    }

    // Do something as a result
    void ArmWarhead() { }
}

Unsubscribing from an Event

To unsubscribe from an event, you can use the Unsubscribe method of the EventBus module. Perhaps in our example above, it makes sense to unsubscribe from the MissileLaunchedEvent once the missile has been launched.

MissileGuidanceModule.cs
public class MissileGuidanceModule : BaseExtensionModule
{
    // Handle the event
    public override void HandleEvent(IEvent e, object eventData)
    {
        if (e is MissileLaunchedEvent)
        {
            // Unsubscribe from the event
            Mother.GetModule<EventBus>().Unsubscribe<MissileLaunchedEvent>(this);

            // Do more stuff
            // ...
        }
    }
}

You can easily check if a module is subscribed to an event by using the IsSubscribed method of the EventBus module.

MissileGuidanceModule.cs
MissileGuidanceModule module = Mother.GetModule<MissileGuidanceModule>();

bool subscribed = Mother.GetModule<EventBus>()
                        .IsSubscribed<MissileLaunchedEvent>(module);
Last Updated: 9/28/25, 8:12 PM
Contributors: Luke Morrison, lukejamesmorrison
Prev
Configuration
Next
Intergrid Message Service