Unity 2021.3+ OpenUPM Apache-2.0

Lightweight C# event distribution

Typed messages. Clean Unity gameplay code.

MBus is a small message bus for Unity projects, built for sending typed C# messages between components without wiring direct scene references. Subscribe by type or value, dispatch through one bus, and let MonoBehaviour lifecycle helpers clean up listeners.

openupm add com.melchart.mbus
GameplayEvents.cs
public readonly struct PlayerHit
{
    public readonly int Damage;
    public PlayerHit(int damage) => Damage = damage;
}

mBus.SubscribeUntilDisabled<PlayerHit>(
    OnHit, this);
mBus.SendMessage(new PlayerHit(25));
PlayerHit HUD, Audio, Stats

Install

Add MBus to a Unity project in one command.

Use OpenUPM for the fastest setup, or install a tagged release through Unity Package Manager with a Git URL.

OpenUPM

openupm add com.melchart.mbus

Git URL

https://github.com/PMelch/MBus.git?path=package#v1.3.0

API shape

Small surface area, useful distribution patterns.

Typed messages

Send classes, structs, strings, enums, and base-type messages through the same bus.

Subscribe<T>(handler)

Value subscriptions

Route enum or constant-style messages when a full message object is unnecessary.

Subscribe(handler, value)

Lifecycle cleanup

Attach listener lifetime to a MonoBehaviour being disabled or destroyed.

SubscribeUntilDestroyed<T>(...)

Predictable nested sends

Messages sent while handlers are running are queued, then delivered after the current dispatch.

SendMessage(message)

Examples

Publish events without coupling gameplay systems.

Use DI when you can, a global instance when you need one.

MBus does not dictate how you keep the bus instance. Bind it through Zenject or another DI container for larger projects, or use MBusInstance for a simple global route.

Open the full README
Signals.cs
public enum UiSignal
{
    PauseOpened,
    PauseClosed
}

mBus.Subscribe(
    OnPauseOpened, UiSignal.PauseOpened);
mBus.SendMessage(UiSignal.PauseOpened);

mBus.SubscribeUntilDestroyed<object>(
    OnAnyMessage, this);