Build Your Own Health and Shield Bars
Build Your Own Health and Shield Bars
Do you want your Fortnite island to look unique? The default health bars can feel boring. We will make custom bars that match your island's theme. You will learn how to track health and shields in Verse.
What You'll Learn
- How to use variables to store numbers.
- How to use functions to update your UI.
- How to connect Verse code to your visual bars.
- How to make a simple HUD (Heads-Up Display).
How It Works
Think of health like a water bottle. The bottle has a max size. The water inside is your current health. When you take damage, the water level drops. We need to track two levels: water (health) and ice (shield).
In Verse, we use variables for these levels. A variable is like a box that holds a number. We will create a box for health. We will create another box for shields.
We also need a function. A function is a recipe. It tells the game what to do. Our recipe will check if the player got hurt. If they did, it will lower the health number. Then, it will update the bar on the screen.
We will use events. An event is like a trigger. When a player takes damage, the event fires. Our code catches this event. It then updates our bars. This makes the game feel alive and responsive.
Let's Build It
We will create a simple script. It will track health and shields. It will print messages to the chat. This helps you see the code working. Later, you can connect this to real visual bars.
First, open UEFN. Create a new Verse file. Name it HealthBarScript.
Here is the code. Copy it carefully.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Native }
using { /UnrealEngine.com/Temporary/Diagnostics }
# This is our main script class.
# It holds all our health logic.
health_manager := class(creative_device):
# This is a variable for health.
# It starts at 100.
# Think of it as a box holding the number 100.
var CurrentHealth : float = 100.0
# This is a variable for shields.
# It starts at 50.
var CurrentShield : float = 50.0
# This function updates the health bar.
# It takes the new health value as input.
UpdateHealthBar(NewHealth : float) : void =
# Check if the new health is valid.
# Health cannot be negative.
if (NewHealth < 0.0):
set CurrentHealth = 0.0
else:
set CurrentHealth = NewHealth
# Print a message to see it working.
Print("Health is now: {CurrentHealth}")
# This function updates the shield bar.
UpdateShieldBar(NewShield : float) : void =
# Check if the new shield is valid.
if (NewShield < 0.0):
set CurrentShield = 0.0
else:
set CurrentShield = NewShield
# Print a message to see it working.
Print("Shield is now: {CurrentShield}")
# This is an event.
# It runs when the actor starts.
OnBegin<override>() <suspends> : void =
# Say hello when the game starts.
Print("Health System Started!")
Print("Starting Health: {CurrentHealth}")
Print("Starting Shield: {CurrentShield}")
Walkthrough
Let's look at the important parts.
var CurrentHealth : float = 100.0: This creates a variable. Thevarkeyword means the number can change later. It holds a decimal number. We set it to 100. This is your starting health.UpdateHealthBar: This is a function. It takesNewHealthas an argument. An argument is data you give to the function. The function checks if the health is too low. It updates the variable using thesetkeyword. It then prints a message.OnBegin: This is an event. It runs automatically when the game starts. It prints the starting values. This helps you debug. Debugging means finding and fixing errors.
Connecting to Visuals
This code tracks the numbers. To show them on screen, you need a UI widget. In UEFN, you create a UMG widget. You add a bar element. You link the bar to the CurrentHealth variable. This part is done in the editor. The Verse code handles the logic. The editor handles the look.
Try It Yourself
Can you add a function to take damage? Create a function called TakeDamage. It should take a number called Amount. It should subtract Amount from CurrentHealth. Then call UpdateHealthBar.
Hint: Use the minus sign - to subtract numbers. Call your new function from OnBegin to test it.
Recap
You made a health system in Verse. You used variables to store numbers. You used functions to update those numbers. You used events to start the code. This is the foundation of game logic. Now you can build cool health bars for your island.
References
- https://dev.epicgames.com/documentation/en-us/fortnite/making-custom-health-and-shield-bars-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/making-custom-backplates-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/making-custom-health-and-shield-bars-in-unreal-editor-for-fortnite
- https://github.com/vz-creates/uefn
- https://github.com/vz-creates/uefn
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add Making Custom Health and Shield Bars to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.
References
Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.