Home Unreal Engine

UE4 technical tutorials chapter 2 - Healer pad - custom actors, actor components

grand marshal polycounter
Offline / Send Message
Obscura grand marshal polycounter
This is the second chapter of my technical tutorial series. In this chapter, I will show you how to make a custom healer pad, that heals the player, when he is standing in it. It will be also able, to run out of charge.

Chapter 2 - Healer pad - custom actors, actor components

--- beginner level ---

End result:
[ame="http://www.youtube.com/watch?v=GKXyPQbxeFw"]http://www.youtube.com/watch?v=GKXyPQbxeFw[/ame]

If you are just starting with blueprints, and such topics, you'll need the first chapter which can be found here:
http://www.polycount.com/forum/showthread.php?t=158846


As the title also tells, I will use a custom actor for making the healer pad. Actors can have components. These components can be specific types of another actors. Like you can have an actor, which has a static mesh, and a point light component. The child components are attached to the parent actor, so whenever its moved, or any transform of it has been changed, the child actors (components) will also get changed.

The healer pad will be built up from these components:

KihWtsu.jpg

- 2 skeletal mesh components: they are skeletal meshes, because I wanted to use spin animation on the light beams. The light beams also has its own material, because I wanted to change its opacity based on the healer pad's charge state.

- collision component: This is a simple box collision component set to block all actors. I added this so the player can step up onto the healer pad.

- Capsule collision component: This is a capsule shaped collision component, and it will be used as a trigger, to know when the player enters the healer pad. The collision preset of it is set to overlap.

- Widget component: This will be used to display the current charge of the healer pad. The value on it will change when the charge gets lower value.


I started with imported my skeletal mesh, and anim sequence for the spin anim. Then I made this material for the light beams:
71fFOHb.jpg

I kept the parameter collection from the previous tutorial, but I added a new parameter into it, called "healingpad". This value will change based on the charge. The light beams will fade out based on the charge value...

After that I created a new blueprint->actor. This will be the healer pad class.

I added these components, and variables into it:
If6HIDm.jpg

I described the components earlier, so I won't go into details with it now.
Variables:

- isonhealingpad (boolean) - this is used to know if the player is standing in the healer pad.

- player - This is a reference to my player character, so I won't have to cast to it every time when I want to change a variable in it.

- Maxvalue (editable float) - This is used to set the max charge of the healer pad.

- currentvalue (float) - Not much to say about this, it will store the current charge :).

- healrate (editable float) - This will be used to set the heal rate. The delay between each healing impulse.

- Platform_healamount (editable float) - This will be used to set how much it should heal the player per impulse.


Editable variables can be changed per instance. So if I would have 2 healer pads in the level, each could have its own values.

Here is the blueprint web of the healer pad:
87Hkk7s.jpg


Event BeginPlay - This event gets fired when the game is started. After the game is tarted, I start playing the spin animation sequence on both skeletal mesh components. After that, I set the "currentvalue" (current charge) to the "maxvalue" (max charge). Then I cast to the player, and set my player reference to be equal to the player, so I won't have to cast to it anymore, when I want something to it.

OnComponentBeginOverlap (platform_trigger) - This event gets fired, when the player enters the trigger of the healer pad. I set the "isonhealingpad" boolean to be true. Then I set the player's "healamount" variable to be equal to this healer platform's heal amount (platform healamount). Then I start looping the "heal" custom event in the player. In this loop, first I check if the player is on max health. Then I don't want to heal it. If it isn't on max health, then I want to start subtracting from the healer pad's charge, as it heals the player. This is done with subtracting the "platform healamount" from its current charge (currentvalue) then I set the current value, to be equal to the result of the previous subtraction. Then I set the healingpad collection parameter, to change the opacity of the light beam (it should fade as the healer pad loose charge). As the scalar collection parameter should be between 0 and 1, and my max charge value and current charge value is greater than 1, I do a lerp to calculate the needed value for the scalar collection parameter. After its calculated, I have a delay, and the duration of is is my "healrate" variable. Then I check if the player is still standing in the healing pad. If yes, then I check if the healing pad still have charge, or not. If it has, then the loop gets restarted.

OnComponentEndOverlap (platform_trigger) - This event gets fired when the player leaves the healing pad. I simply set the "isonhealingpad" boolean to be false, so the healing loop gets stopped.

The healer pad script is done.

Now lets see what to change in the player's blueprint.

Its still almost the same as in the previous tutorial. There are only small differentces. One is that now I have a max health variable and now the player can have health value that is greater than 1.

Yp4QEW9.jpg
J0dAp3i.jpg


Widget to display the charge of the healer pad:

Previously we added a widget components for this into the healer pad. A specific widget can be assigned into it. For this, I created one widget, with a text in it, and the text has an event binded to it, to get the current charge of the healer pad:

mU20dKB.jpg

This solution works only with the first healer pad in the level, because I get the first actor from the array of the healingpad class! To make it working with multiple healing pads, you can store a value in the player, to know which pad its standing in.

Note - If you use a text renderer for this, instead of a widget, you don't need to determine which healing pad you are standing in, it can know it by default, because it would run inside the healer pad blueprint instance. Its also easier to set up, because the only thing you need to do, is to set the text renderer's value to be the current charge value of the healer. Then your healer platform is fully modular, and you can place any amount in your level, without having to do any extra work. For getting the light beam to also work individually on each healer pad, you can use dynamic material instances.



Now the healer pad is done!
Sign In or Register to comment.