Comment on page
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.
In the modal that opens, scroll down and select BP_BaseCharacterCurvedComponent.
Name it BP_HealthComponent.
To do so, get the
Character Core Componentand from there the
Character. Drag the
Characterreference, create a
Bind Event to On Player Landednode 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
Now our component is ready for testing! To test if our Event Handler is actually called, add a
Print Stringnode inside of
Handle on Player Landed.
For our new component to run we simply need to add it to our Character Blueprint. Open
Add Componentin the Components tab, search for the new Health Component and select it.
That's it already! Now to test if the previously added
Print Stringnode is actually called, hit the Play button in your editor's toolbar and jump. When landing, a message should appear on your screen.
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
Floatand name it
Health. Set it's default value to 100 in the
Detailstab and then replace the code inside of
Handle on Player Landedwith the following code:
Create a new variable of Type
bShowDebugInformation. Set it`s default value to
Trueand create a new function
Print Debug Informationand add the following code:
Then call it in
Event Tickas follows:
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!
Last modified 8mo ago