# Event System

Since version 0.9.1 **Game Creator** comes with a fully fledge **Event System** that is built on top of **Triggers** and **Actions** for maximum flexibility.

## Event System 101

When a game object (yellow) wants to communicate a state change to other game objects (blue ones) it normally has to iterate over all these objects and notify them one by one about the change.

![](https://2174264233-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAqwYovmUPn5V6CMeID%2F-Le6TYnHCQylwTJMmMUg%2F-Le6bTfxxg3Vgc1rjkO7%2Fevent-system-old.jpg?alt=media\&token=4f51e811-d2da-4fdb-9bf4-d99c009a39dd)

This is okay for small scale and non-dynamic systems, but it can quickly become a mess. An **Event System** flips the system upside down, making objects *subscribe* to a proxy that observes the object with the state change, and communicates it when the change happens.

![](https://2174264233-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAqwYovmUPn5V6CMeID%2F-Le6TYnHCQylwTJMmMUg%2F-Le6cBVPX8HS3M3Ugrib%2Fevent-system-new.jpg?alt=media\&token=aa5e0578-932b-47d5-b532-1745f1311aad)

By doing so we translate the responsibility of keeping a list of objects that need to be notified from the yellow object to each individual blue object.

## Dispatch an Event

To dispatch an **Event** all that is needed is to call the **Dispatch Event Action**. This **Action** needs a string field which is the **name** of the event.

![(A Dispatch Event Action using "my-event" as the name of the Event)](https://2174264233-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAqwYovmUPn5V6CMeID%2F-Le6TYnHCQylwTJMmMUg%2F-Le6i_9wXpWMvfRoE_2J%2Fevent-system-action.jpg?alt=media\&token=6df6dc08-e26b-42ed-b0bb-d5b0e8bb581c)

{% hint style="info" %}
The name of the **Event** dispatched can be whatever the developer wants.
{% endhint %}

## Receive an Event

An object can listen to events dispatched using the **On Receive Event Trigger**. This **Trigger** will be called every time an event with a specific name is raised.

![(Trigger set to detect when a "my-event" Event is dispatched)](https://2174264233-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAqwYovmUPn5V6CMeID%2F-Le6TYnHCQylwTJMmMUg%2F-Le6kLvw7S2FuUtMvLPt%2Fevent-system-trigger.jpg?alt=media\&token=7b5ea1d9-e7e2-4f60-81ae-8177a4e074f5)

Optionally, the invoker of this event can be saved in a **Variable** to lately reference the caller from within an **Action** or a **Condition**.
