OpenUPM
openupm add com.melchart.mbus
Lightweight C# event distribution
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
public readonly struct PlayerHit
{
public readonly int Damage;
public PlayerHit(int damage) => Damage = damage;
}
mBus.SubscribeUntilDisabled<PlayerHit>(
OnHit, this);
mBus.SendMessage(new PlayerHit(25));
Install
Use OpenUPM for the fastest setup, or install a tagged release through Unity Package Manager with a Git URL.
openupm add com.melchart.mbus
https://github.com/PMelch/MBus.git?path=package#v1.3.0
API shape
Send classes, structs, strings, enums, and base-type messages through the same bus.
Subscribe<T>(handler)
Route enum or constant-style messages when a full message object is unnecessary.
Subscribe(handler, value)
Attach listener lifetime to a MonoBehaviour being disabled or destroyed.
SubscribeUntilDestroyed<T>(...)
Messages sent while handlers are running are queued, then delivered after the current dispatch.
SendMessage(message)
Examples
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.
public enum UiSignal
{
PauseOpened,
PauseClosed
}
mBus.Subscribe(
OnPauseOpened, UiSignal.PauseOpened);
mBus.SendMessage(UiSignal.PauseOpened);
mBus.SubscribeUntilDestroyed<object>(
OnAnyMessage, this);