Unreal Engine Tutorial - Character Health Displayed In A Widget -
Unreal Engine Tutorial - Character Health
๐Hi, and thanks for watching my video!๐
In this video, I am adding health to my character and displaying it in a widget over the character's head.
- Daniel, from ๐ https://www.bloghoarder.com/ ๐
What we will do:
Add "health" variable to the character.
Damage character with the enemy attack.
Show character health and damage with a widget over the character's head.
Start the level over when the character's health reaches 0.
Here's how to do it:
Character Blueprint
Inside the character blueprint, add a new variable (integer) and name it health.
Compile and set the health value to 100.
Enemy Blueprint (collision that damages character)
Add a box collision to an enemy weapon.
On "Component Begin Overlap" cast to character with "health."
Get "health."
Subtract 10 "health".
Set "health" with the subtracted "health" value.
Character's Health Widget (displayed overhead of character)
Create a "health widget" from the content browser.
In the widget, add a "canvas panel."
In the top right-hand corner select "Custom Size" and Size it 100x200.
Add a "progress bar" to the "canvas panel."
Size the bar and anchor it.
Under "Appearance" you can change the colour of the progress bar.
Under "Progress" change the "percentage" to 100.
Click "bind" and "create binding."
In the binding, cast to the character, drag "get player pawn" from the object input.
"Get health", from the character and connect the health to the return node.
Drag off the conversion node and "divide."
Input to divide 100 and then plug the division result into the return node.
Back in the character's blueprint
Select the character's mesh.
Add a widget.
In widget details, under "user interface" chose the health widget from the "widget class."
Change the "draw size" to match the widget's custom size.
In the "event graph" drag off of the "event tick" cast to a branch.
"Get health" and drag off for a "less than or equal" and leave number as 0.
Here is a level transition tutorial.
https://www.youtube.com/watch?v=9U_U7Dx9Ce4&list=PLAMN4WCH4g9J6C-2goigkmm_oDkcSzecH&index=3&t=1s
Here are the steps from the level transition tutorial.
Create Widget (select your loading screen widget - Add to viewport - Delay (keep time at .2) - Open level by name (insert name of level).
Thanks again for watching!
Be well and have a great day.
Consider checking out my website ๐ https://www.bloghoarder.com/ ๐
Other Videos By Blog Hoarder
Other Statistics
Widget Statistics For Blog Hoarder
Blog Hoarder currently has 936 views spread across 2 videos for Widget. Less than an hour worth of Widget videos were uploaded to his channel, less than 0.47% of the total video content that Blog Hoarder has uploaded to YouTube.