# On Owner Killed

The "On Owner Killed" event dispatcher is an event that is fired whenever the health of an instance of the RHS Component goes 0 or below and therefore the owner of the component is killed. You can bind to this event dispatcher to execute logic in any other blueprint whenever the owner gets killed.

***

{% hint style="info" %}
Event Dispatchers do not manipulate any data within the component, so they are a good solution for attaching your custom logic to various events within the Replicated Health System component without actually having to access the component's internal logic. Click here to read more about [Event Dispatchers](https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/Blueprints/UserGuide/EventDispatcher/).
{% endhint %}

## How to bind

Using event dispatchers is quite simple. Suppose you have some sort of blueprint class in which you want to perform external logic when a particular event dispatcher is invoked. To bind to an event dispatcher, you must first get a reference to the specific component you want to bind to. Once you have the reference, you can follow the steps below to bind to any event dispatcher contained in the RHS component.

#### Create a custom event to call when you want to bind

To create a binding to one of the component dispatchers, you need to create a custom event in your event graph that you can call to bind to your selected dispatchers. Typically, you will bind to all event dispatchers once at the start of the game, but you are free to use this logic as you wish, as there is no predefined way of knowing exactly when to bind.

<figure><img src="https://3987143181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVfCkT8z6ejXZQNVtZ3ai%2Fuploads%2FNmCDoEoabg3hlXsxWRM6%2Fdispatch-custom-event.png?alt=media&#x26;token=32eda3a3-0568-407a-b025-0c0c908a0d9b" alt=""><figcaption></figcaption></figure>

#### Binding to the desired event dispatcher

Drag from the component reference and find the event dispatcher of your choice. In this example, we will use the event dispatcher "MyDispatcher", which is not included in the system you can purchase from the marketplace. To bind to an event dispatcher, you need to search: "Bind event to \[name of dispatcher]".

<figure><img src="https://3987143181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVfCkT8z6ejXZQNVtZ3ai%2Fuploads%2FWxEhgLWlYrTDyqldpUCB%2Fdispatcher-bind.png?alt=media&#x26;token=76f66155-c66e-4489-be7c-d2346c170338" alt=""><figcaption></figcaption></figure>

On the "Bind Event to \[Dispatcher Name]" node, you will see a red squared pin named "Event". From this pin, you can now drag to another custom event that you have created specifically for this dispatcher, or to an existing event that you want to run when the event dispatcher is called. In this example, we will create a new custom event and bind it to the "MyDispatcher" event dispatcher.

<figure><img src="https://3987143181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVfCkT8z6ejXZQNVtZ3ai%2Fuploads%2FOLK4YCxIl2XHnfIEun9q%2Fdispatcher-bind-evemt.png?alt=media&#x26;token=bb6dc2fe-b643-476a-9bd9-590308658261" alt=""><figcaption></figcaption></figure>

#### Executing Logic on the new Disatcher Event

Now we basically have an event that we call whenever we want to bind to a particular dispatcher. The dispatcher itself is connected to another custom event that will be executed from there when the event dispatcher is called. From here, you can attach any kind of custom logic to the event you just created. In this example, we will show you how to print "Hello World" using the custom dispatcher event we created in the previous steps.

<figure><img src="https://3987143181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVfCkT8z6ejXZQNVtZ3ai%2Fuploads%2FveRLPXb5zgO5sDBj1VsQ%2Fdispatcher-custom-logic.png?alt=media&#x26;token=eb21e95f-e749-4e38-82ed-dc51f83e1905" alt=""><figcaption></figcaption></figure>

Using the "Print String" node, we will now print "Hello World" to the player's screen every time the "MyDispatcher" event dispatcher is called. Of course, this is a very simple example, but you can basically connect any other logic you like here, including but not limited to functions, macros, custom blueprint logic, or other events in your blueprint.

For now, you should have a working binding to an event dispatcher from the RHS component. Note that the "MyDispatcher" event dispatcher is not included in the system and is used for demonstration purposes only. The result of our logic should look like this:

<figure><img src="https://3987143181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVfCkT8z6ejXZQNVtZ3ai%2Fuploads%2Fyxxo8SWcmvShxCk0zopX%2Fdispatcher%20result.png?alt=media&#x26;token=7b501a07-f720-42f1-8089-2425a1de46e7" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Note that when you bind to an event dispatcher, the event that executes the binding, which in our case is the "Bind to Dispatcher" event, must be executed only once! After binding to a dispatcher, the new custom event (in this example, "My Dispatcher Event") will be able to be called until you unbind it.[ Learn more.](https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/Blueprints/UserGuide/EventDispatcher/BindingAndUnbinding/)
{% endhint %}

#### Unreal Engine Documentation

This guide on how to bind to event dispatchers was a fairly basic introduction on how you can use the event dispatcher included in the Replicated Health System Component. If you wish to better understand how you can work with event dispatchers in Unreal Engine or how you can create your own dispatcher events, please refer to the[ Unreal Engine Documentation](https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/Blueprints/UserGuide/EventDispatcher/). Below you will find some useful links about event dispatchers:

{% embed url="<https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/Blueprints/UserGuide/EventDispatcher/BindingAndUnbinding/>" %}

{% embed url="<https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/Blueprints/UserGuide/EventDispatcher/Calling/>" %}

{% embed url="<https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/Blueprints/UserGuide/EventDispatcher/CreatingEvents/>" %}

#### In Summary

<table data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td></td><td>Learn how to create your own event in order to bind to any dispatcher.</td><td></td><td><a href="https://3987143181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVfCkT8z6ejXZQNVtZ3ai%2Fuploads%2FNmCDoEoabg3hlXsxWRM6%2Fdispatch-custom-event.png?alt=media&#x26;token=32eda3a3-0568-407a-b025-0c0c908a0d9b">dispatch-custom-event.png</a></td><td></td></tr><tr><td></td><td>How to access the bind node for a certain event dispatcher.</td><td></td><td><a href="https://3987143181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVfCkT8z6ejXZQNVtZ3ai%2Fuploads%2FWxEhgLWlYrTDyqldpUCB%2Fdispatcher-bind.png?alt=media&#x26;token=76f66155-c66e-4489-be7c-d2346c170338">dispatcher-bind.png</a></td><td></td></tr><tr><td></td><td>Bind a custom event to the event dispatcher using the bind node.</td><td></td><td><a href="https://3987143181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVfCkT8z6ejXZQNVtZ3ai%2Fuploads%2FOLK4YCxIl2XHnfIEun9q%2Fdispatcher-bind-evemt.png?alt=media&#x26;token=bb6dc2fe-b643-476a-9bd9-590308658261">dispatcher-bind-evemt.png</a></td><td></td></tr><tr><td></td><td>Add logic to your new custom event, bound to the event dispatcher.</td><td></td><td><a href="https://3987143181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVfCkT8z6ejXZQNVtZ3ai%2Fuploads%2FveRLPXb5zgO5sDBj1VsQ%2Fdispatcher-custom-logic.png?alt=media&#x26;token=eb21e95f-e749-4e38-82ed-dc51f83e1905">dispatcher-custom-logic.png</a></td><td></td></tr><tr><td></td><td>Testing the results of the new custom binding.</td><td></td><td><a href="https://3987143181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVfCkT8z6ejXZQNVtZ3ai%2Fuploads%2Fyxxo8SWcmvShxCk0zopX%2Fdispatcher%20result.png?alt=media&#x26;token=7b501a07-f720-42f1-8089-2425a1de46e7">dispatcher result.png</a></td><td></td></tr><tr><td></td><td>Check the official Unreal Engine Documentation for more free learning resources.</td><td></td><td><a href="https://3987143181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVfCkT8z6ejXZQNVtZ3ai%2Fuploads%2FLSLCm6Qo6pIXqaJih0oS%2Funreal-doc.png?alt=media&#x26;token=2ccb39b2-fb09-460d-b1e7-f44aad226c15">unreal-doc.png</a></td><td><a href="https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/Blueprints/UserGuide/EventDispatcher/">https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/Blueprints/UserGuide/EventDispatcher/</a></td></tr></tbody></table>
