# Evently

Evently is a lightweight and flexible event bus system for Unity designed to simplify communication between different parts of a game or application.

Instead of relying on direct references between objects, Evently allows systems to communicate through events. One system can publish an event, while other systems subscribe to it and react when it occurs. This approach helps decouple game logic, making systems easier to maintain, extend, and reuse.

By using an event-driven architecture, Evently reduces tight dependencies between components and encourages a more modular project structure. Systems no longer need to know about each other directly — they only need to agree on the events being exchanged.

Evently provides a simple and type-safe API for subscribing to events, publishing event data, and managing listener lifetimes. It supports both a global event bus for project-wide communication and scoped buses for isolated systems, allowing developers to structure event flows according to their architecture.

Because Evently is built specifically for Unity workflows, it integrates cleanly with MonoBehaviour lifecycles and supports automatic listener disposal, making it easier to avoid common issues such as forgotten subscriptions or dangling listeners.

***

### <mark style="color:$success;">What Counts as an Event</mark>

Any **class** or **struct** can be used as an event payload. This allows you to pass data-rich objects between systems without tightly coupling them. Avoid using primitive types for events with semantic meaning, as dedicated event types make the intent clearer and easier to maintain.

***

### <mark style="color:$success;">Optional Settings</mark>

Evently provides several optional configuration flags that allow you to adjust how the event system behaves.\
These settings are defined as static properties on the `Evently` class and can be configured at runtime, typically during project initialization.

#### **PreventDuplicateSubscriptions**

Controls whether Evently prevents the same handler from being subscribed multiple times to the same event type.

When this option is enabled, Evently checks existing listeners before registering a new one. If the same handler is already subscribed for the event type, the system will not register it again and will instead return the existing listener.

This helps avoid situations where a handler is accidentally subscribed multiple times, which would otherwise result in the handler being invoked repeatedly for a single event dispatch.

This option is particularly useful in larger projects where subscriptions may happen from multiple initialization paths.

{% code fullWidth="false" %}

```csharp
Evently.PreventDuplicateSubscriptions = true;
```

{% endcode %}

#### **EnableLogging**

Controls whether Evently logs exceptions thrown inside event handlers.

If enabled, any exception that occurs during event dispatch will be caught and logged using Unity's logging system. This prevents one faulty listener from breaking the entire event chain and helps identify issues during development.

When disabled, Evently will still safely catch exceptions internally, but no log output will be generated.

This setting is typically enabled during development to make debugging easier, and can be disabled in production builds to reduce unnecessary logging overhead.

{% code fullWidth="false" %}

```csharp
Evently.EnableLogging = true;
```

{% endcode %}
