# Creating a component

This page explains how to create a new component for Motion to extend Motion to your needs. In this example we will create a *Health Component* which adds a Health value to the Motion Character which we can then use to implement **fall damage**.

### Creating a Motion Component

To begin, we need to create a new [Actor Component](https://docs.unrealengine.com/en-US/API/Runtime/Engine/Components/UActorComponent/index.html) by right-clicking in the [Content Browser](https://docs.unrealengine.com/en-US/Basics/ContentBrowser/index.html) and selecting **Blueprint Class**.

<figure><img src="https://2932027479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fm8ONMNsOi1sD5UhoMlyb%2Fuploads%2FfU0mcbt9lmped5cStq8q%2Fue5-create-component.png?alt=media&#x26;token=6b36fb23-fc2b-4258-b557-1e856cefa105" alt=""><figcaption></figcaption></figure>

In the modal that opens, scroll down and select **BP\_BaseCharacterCurvedComponent**.

<figure><img src="https://2932027479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fm8ONMNsOi1sD5UhoMlyb%2Fuploads%2FQ2fXkpcgr7hOTwb46r4o%2Fue5-cb-createcomponent2.png?alt=media&#x26;token=5e6b6290-0f5d-4c07-bdf7-00faae1b91bb" alt=""><figcaption></figcaption></figure>

Name it **BP\_HealthComponent**.

![](https://2932027479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fm8ONMNsOi1sD5UhoMlyb%2Fuploads%2FLvm3j2RYnPDHkKBwOkvc%2Fue4-motion-contentbrowser-healthcomponent.png?alt=media\&token=8681a7b6-5b93-48d3-afe8-928a9a281ef7)

Double-clicking it will show you the empty [Event Graph](https://docs.unrealengine.com/en-US/ProgrammingAndScripting/Blueprints/UserGuide/EventGraph/index.html).

<figure><img src="https://2932027479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fm8ONMNsOi1sD5UhoMlyb%2Fuploads%2FKDO1dAkPAAAWJBbAjYGy%2Fue5-motion-healthcomponent-eg.png?alt=media&#x26;token=655ec09f-a05f-4417-9017-c8442148e10a" alt=""><figcaption></figcaption></figure>

### Listening to Event Landed

Since the Character Blueprint already comes with a [Event Dispatcher](https://docs.unrealengine.com/en-US/ProgrammingAndScripting/Blueprints/UserGuide/EventDispatcher/index.html) for `OnPlayerLanded` we can just subscribe to that!

To do so, get the `Character Core Component` and from there the `Character`. Drag the `Character` reference, create a `Bind Event to On Player Landed` node and createa a new custom Event to it.

Then create a new function named `HandleOnPlayerLanded`. Inside this function we will place the code that is executed when the event fires.

Connect it to the `EventOnPlayerLanded` node.

### Testing the Event Handler

Now our component is ready for testing! To test if our Event Handler is actually called, add a `Print String` node inside of `Handle on Player Landed`.

![](https://2932027479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fm8ONMNsOi1sD5UhoMlyb%2Fuploads%2FmRJSXCbGrmvckrclTVYU%2Fue4-motion-healthcomponent-handler-test.png?alt=media\&token=a1001507-acf3-4bf7-b01f-6d909ebe4064)

### Adding Component to Character

For our new component to run we simply need to add it to our Character Blueprint. Open `BP_MotionCharacter`, press `Add Component` in the Components tab, search for the new Health Component and select it.

That's it already! Now to test if the previously added `Print String` node is actually called, hit the Play button in your editor's toolbar and jump. When landing, a message should appear on your screen.

### Adding simple damage logic

This example will only cover a simple example solution for damage. Feel free to adjust and extended the logic as needed for your project.

Add a variable of Type `Float` and name it `Health`. Set it's default value to 100 in the `Details` tab and then replace the code inside of `Handle on Player Landed` with the following code:

<figure><img src="https://2932027479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fm8ONMNsOi1sD5UhoMlyb%2Fuploads%2F9Fa25VkfbjfN9zWHpl8w%2Fue4-motion-healthcomponent-handler-samplesolution.png?alt=media&#x26;token=602a61da-d157-4b09-8a22-07f82b0bc972" alt=""><figcaption></figcaption></figure>

Create a new variable of Type `Boolean` called `bShowDebugInformation`. Set it\`s default value to `True` and create a new function `Print Debug Information` and add the following code:

<figure><img src="https://2932027479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fm8ONMNsOi1sD5UhoMlyb%2Fuploads%2FxSPvXBXXZcMeN7f2BibC%2Fue4-motion-healthcomponent-debug.png?alt=media&#x26;token=50076bf7-72f2-4476-8ffb-20de815ddfbc" alt=""><figcaption></figcaption></figure>

Then call it in `Event Tick` as follows:

<figure><img src="https://2932027479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fm8ONMNsOi1sD5UhoMlyb%2Fuploads%2FGQJY9uaNY91Tf4PQ1oWB%2Fue4-motion-healthcomponent-eventtick.png?alt=media&#x26;token=c6c6949f-158f-499c-a28e-2f88cbb828b2" alt=""><figcaption></figcaption></figure>

Hit the Play button in your editor's toolbar again and it should look like this now when you jump and land:

You have successfully created a component for Motion! Congratulations!
