> For the complete documentation index, see [llms.txt](https://asperazera.gitbook.io/simple-event-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://asperazera.gitbook.io/simple-event-system/advanced/unsubscribing.md).

# Unsubscribing

Since Simple Event System uses a global **Event Dispatcher**, "unsubscribing" can mean two things: either ignoring the event logically or completely severing the connection.

Here are the three ways to handle stopping events.

***

### 1. Automatic Cleanup (Destroy Actor)

**Best for:** Dead enemies, destroyed items, or level transitions.

You generally **do not need** to manually unsubscribe actors that are being destroyed.

Unreal Engine's Event Dispatcher system uses "weak references". When you call `Destroy Actor`, the engine automatically removes that actor from all dispatchers it was listening to.

{% hint style="info" %}
**Info:** You don't need to write any cleanup logic in the `EndPlay` event. It works out of the box.
{% endhint %}

***

### 2. Logical "Pause" (Enum/Boolean Filter)

**Best for:** Temporarily ignoring events (e.g., player is stunned) or stopping reaction to one specific tag while keeping others active.

Since you bind to the *Global Dispatcher*, you cannot "unbind" from just one specific tag (like `Game.Green`) while keeping `Game.Red`. Instead, use a **Enum** or **Boolean Variable** to gate the logic.

#### Implementation

1. Create a Boolean variable in your Actor (e.g., `bIsListening` or `bCanReceiveDamage`).
2. In your Event Graph, right after the **OnEventReceived** node (and before your Tag Switch), add a **Branch**.
3. Connect your boolean to the Branch.

* **True:** Continue to the `Switch on Gameplay Tag` node.
* **False:** Do nothing.

This effectively "mutes" the events without breaking the connection.

***

### 3. Dynamic Filtering (Tag Container)

**Best for:** Advanced actors that need to "subscribe" or "unsubscribe" from **specific** events on the fly during gameplay (e.g., unlocking a specific quest stage or enabling a feature).

Instead of using multiple Boolean variables or unbinding the whole system, you can maintain a local **"Whitelist"** of tags that the actor is currently listening to.

#### Implementation

1. Create a variable in your Actor (e.g., named `BindedEvents`).
2. Set its type to **Gameplay Tag Container**.
3. In your Event Graph, immediately after receiving the event, check the incoming **Event Tag**.
4. Use the node **Matches Any Tags** (Container).
5. Connect your `BindedEvents` variable to the **Other Container** pin.
6. Connect the result to a **Branch**.

If the incoming tag exists in your container, the Branch opens, and logic executes.

<figure><img src="/files/sIB421EPlaycmEjjmHhO" alt=""><figcaption></figcaption></figure>

#### How to Control (Subscribe/Unsubscribe)

You can now modify this list at runtime using standard container nodes:

* **To Subscribe:** Use the **Add Gameplay Tag** node on your `BindedEvents` variable (e.g., add `Game.Zone.Enter` when a player spawns).
* **To Unsubscribe:** Use the **Remove Gameplay Tag** node (e.g., remove `Game.Zone.Enter` when the player leaves the area).

<figure><img src="/files/QItGbft0zl3UbXNq2wrH" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Tip:** This effectively allows you to toggle individual event listeners on/off dynamically without breaking the connection to the global dispatcher.
{% endhint %}

### 4. Manual Unbind (Hard Stop)

**Best for:** Optimization, or when an actor changes state completely and should never listen to the Event System again (but remains alive in the world).

If you want to completely stop receiving *any* global events on a specific actor:

1. Get the reference to the **Simple Event System Component** (using `Get Simple Event System`).
2. Drag off the component pin and search for **Unbind All Events from On Global Event**.
3. Call this node when you want to stop listening.

<figure><img src="/files/FmsbBdxpxPw6YtyGGxc7" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
**Warning:** This will stop **ALL** tags for this actor. If you have multiple logic chains listening to the system in the same blueprint, they will all stop working.
{% endhint %}

***

### 📝 Summary

| Method             | When to use?                                                                     |
| ------------------ | -------------------------------------------------------------------------------- |
| **Auto Cleanup**   | When the actor is destroyed. (Happens automatically).                            |
| **Boolean Filter** | Simple On/Off switch for the entire actor.                                       |
| **Dynamic Filter** | **Granular control.** Add or remove specific tags from a "whitelist" at runtime. |
| **Unbind All**     | When the actor is still alive but should completely disconnect from the system.  |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://asperazera.gitbook.io/simple-event-system/advanced/unsubscribing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
