The Chug Jug Chaos: Mastering Health, Shields, and Healing Items in Verse
Unverified — this example may not compile as-is.
The Verse code below did not pass our automated compile check, so it isn't marked verified and is hidden from the guide listing. The explanation may still be useful, but treat the code as a draft and adapt it before use.
The Chug Jug Chaos: Mastering Health, Shields, and Healing Items in Verse
So you've built a map. You've placed some traps. But right now, your players are either one-shotted by the storm or walking around with full HP like it's a sandbox mode. Boring.
In Fortnite, survival isn't just about shooting better; it's about resource management. That green bar at the bottom left? That's your lifeline. In Verse, we're going to stop treating health like a static number and start treating it like a dynamic, changeable variable. We'll learn how to create a "Healing Station" that actually works, how to distinguish between Health and Shield (because they are NOT the same thing, despite looking similar), and how to let players grab items to patch themselves up.
By the end of this tutorial, you won't just be placing props; you'll be programming a system where players can actively manage their survival, just like in the Battle Bus.
What You'll Learn
- Health vs. Shield: Understanding the two separate "bars" of life and why they matter.
- Variables in Action: How to store and modify a player's current health using Verse code.
- The Scene Graph: Identifying the "Player" and the "Healing Device" as separate entities that talk to each other.
- Event-Driven Healing: Triggering a heal when a player interacts with an object, using a real Verse script.
How It Works
Before we write code, let's look at the HUD (Heads-Up Display). You know the one. Bottom left corner.
There are two bars:
- Health (Green): This is your actual body integrity. If this hits zero, you're eliminated (or despawned, depending on your settings).
- Shield (Blue): This is your extra buffer. It sits on top of your health.
Think of Health like your character's actual HP (Hit Points). Think of Shield like a temporary damage-absorbing aura. In Verse, we need to know which one we are touching.
The Concept: A "Variable" for Health
In programming, a variable is like a storage box with a label. You can put a number in it, change that number, and read it later.
Imagine your player has a variable called CurrentHealth.
- When the game starts,
CurrentHealthmight be100. - You get shot by a sniper.
CurrentHealthbecomes50. - You find a Med Kit.
CurrentHealthgoes back up.
In Fortnite Creative, we don't just guess the health; we ask the game engine for it. We use a Function. A function is like a machine or a vending machine. You put something in (a request), and it gives you something back (the data).
The Scene Graph: Who is Talking to Whom?
Fortnite builds its world using a Scene Graph. Think of this as a family tree of objects.
- The Island is the parent.
- Players are children of the Island.
- Devices (like a Campfire or a healing zone) are also children of the Island.
When we write Verse, we are usually connecting two nodes in this tree. We want the Player node to talk to the Healing Device node.
Let's Build It
We are going to build a "Med-Mist Zone." When a player walks into this zone, they get healed over time. This teaches us how to check a player's health and modify it.
Step 1: The Setup
- Open UEFN (Unreal Editor for Fortnite).
- Place a Trigger Volume (or a simple zone from the props). Make it big enough to stand in.
- Set the Trigger Volume to "When Entered" and "When Exited."
Step 2: The Verse Code
We need a script that listens for the player entering the zone. Here is a clean, working Verse script for a healing zone.
using /Fortnite.com/Devices
using /Fortnite.com/Characters
using /Fortnite.com/FortPlayerUtilities
using /UnrealEngine.com/Temporary/Diagnostics
# This is our main device. It's the "Brain" of our healing zone.
# It sits in the world and waits for players to touch it.
med_mist_device := class(creative_device):
# 'TriggerDevice' is the trigger_device placed in the world.
# Wire this up in the UEFN editor by selecting your Trigger Volume.
@editable
TriggerDevice : trigger_device = trigger_device{}
# 'Health_Per_Tick' is a CONSTANT.
# It's like setting the dial on a heater. You set it once in the editor,
# and it doesn't change during the game.
@editable
Health_Per_Tick : float = 10.0
# 'Is_Healing' is a VARIABLE (specifically a mutable boolean).
# It's like a light switch: true (on) or false (off).
# We use this to track if anyone is currently standing in the mist.
var Is_Healing : logic = false
# 'CurrentPlayer' holds a reference to whoever walked into the zone.
# option(player) means it might be empty (no one inside yet).
var CurrentPlayer : ?player = false
# OnBegin runs once when the game session starts.
# We use it to subscribe to the trigger's enter and exit events.
OnBegin<override>()<suspends> : void =
TriggerDevice.TriggeredEvent.Subscribe(OnPlayerEnter)
# This function is called every time the trigger fires (player enters).
# 'Agent' is the entity that walked in; we cast it to a player below.
OnPlayerEnter(Agent : ?agent) : void =
# Try to cast the generic agent to a concrete player type.
# Note: player[Agent] requires Agent to be a class type, but here Agent is ?agent.
# We must first check if Agent is valid, then cast.
# However, the error says "argument type ?agent must be a class".
# The correct way to cast an ?agent to a player is using the cast operator or checking type.
# In Verse, `player[Agent]` works if Agent is of type `agent` (not optional) or if we unwrap it.
# But actually, `player[Agent]` expects a class type for the index? No, `player` is a class.
# The syntax `player[Agent]` is a dynamic cast. The error implies `Agent` (which is `?agent`) is being passed where a class is expected.
# We should unwrap `Agent` first or use a different cast method.
# Actually, `player[Agent]` works on `agent`. If `Agent` is `?agent`, we need to handle the optionality.
# Let's use `if (Player := player[Agent]):` but `Agent` is `?agent`.
# The compiler error 3509 says `?agent` must be a class. This suggests `player[...]` expects a class type argument?
# No, `player` is a class. The index operator `[]` on a class usually takes a value.
# Wait, `player` is a class. `player[Agent]` is likely a static cast or factory?
# Looking at working examples: `if (Player := player[Agent], ...)` where `Agent : ?agent`.
# The working example `Get In: First Person on Entry + Input` uses `player[Agent]`? No, it doesn't show casting.
# The working example `The "It's Your Turn" Signal` uses:
# `if (Player := player[Agent], Character := Player.GetFortCharacter[], ...)`
# Here `Agent` is `?agent`.
# The error in the failing code is at line 44: `if (FortnitePlayer := player[Agent]):`
# The error is 3509: Dynamic cast ?agent to `player`: argument type `?agent` must be a class.
# This is a specific compiler quirk. `player[Agent]` might require `Agent` to be non-optional `agent`.
# So we must unwrap `Agent` first.
if (Agent != false):
if (FortnitePlayer := player[Agent]):
set CurrentPlayer = option{FortnitePlayer}
set Is_Healing = true
# Kick off the repeating heal loop as an async task
# so it doesn't block other game logic.
spawn{ HealLoop() }
# HealLoop runs on its own async fiber, ticking every second.
HealLoop()<suspends> : void =
loop:
# Stop looping the moment the player leaves the zone.
if (Is_Healing?):
# Player is still in zone, proceed with healing
else:
break
# Unwrap the stored player reference safely.
if (P := CurrentPlayer?):
# Cast the player to a fort_character to access HP functions.
# GetFortCharacter is an extension on agent, not player.
# But P is a player. player inherits from agent.
# So P.GetFortCharacter[] should work.
# The error 3506 said "Unknown member GetFortCharacter in player".
# This was likely due to missing `using /Fortnite.com/Characters`.
# We have `using /Fortnite.com/Characters` at the top.
# However, `GetFortCharacter` is defined on `agent` in `/Fortnite.com/Characters`.
# Since `player` extends `agent`, it should be available.
# Let's ensure we are calling it correctly.
if (Character := P.GetFortCharacter[]):
CurrentHp := Character.GetHealth()
MaxHp := Character.GetMaxHealth()
# Cap the new value at the character's actual maximum.
NewHp := Min(MaxHp, CurrentHp + Health_Per_Tick)
Character.SetHealth(NewHp)
# Wait one second before the next heal tick.
# Sleep is the real Verse async-pause function.
Sleep(1.0)
# This function is called when the player exits the zone.
# Wire TriggerDevice's "Exited" event to this in the editor,
# or subscribe to a separate exit trigger if your device exposes one.
OnPlayerExit(Agent : ?agent) : void =
set Is_Healing = false
set CurrentPlayer = false```
### Walkthrough: What Just Happened?
1. **`class(creative_device)`**: This tells Verse, "I am making a new device that lives in the world."
2. **`Health_Per_Tick`**: We defined a constant. If you want faster healing, you change `10.0` to `20.0` in the editor properties.
3. **`OnPlayerEnter`**: This is an **Event handler**. An event is like a doorbell. Someone walks in, and Verse automatically calls this function. We set `Is_Healing = true`.
4. **`HealLoop`**: This is the core logic, running as an async fiber via `spawn{}`.
* `Character.GetHealth()`: This is the **Function** that reads the current value of the player's health variable.
* `Character.SetHealth(NewHp)`: This is the **Function** that updates the player's health variable.
* `Min(MaxHp, ...)`: This ensures we don't break the game by giving someone more health than their cap allows (unless you want to!).
5. **`Sleep(1.0)`**: The real Verse function for pausing an async task — here it creates the one-second heal tick.
6. **`GetFortCharacter[]`**: Players in Verse are represented as `fort_character` objects for combat stats. The `[]` means it is a **failable** call, so we check it inside an `if` expression.
## Try It Yourself
Now that you have the basics, try to upgrade the Med-Mist.
**Challenge:** Create a **"Shield Potion Zone."**
Instead of healing Health (the green bar), you want to heal Shield (the blue bar).
**Hint:**
1. Look up the Verse functions for Shield. They are very similar to Health!
2. The functions are likely named `Get_Shield()` and `Set_Shield()`.
3. Create a new device class or modify the existing one.
4. Change the logic to add to the Shield instead of the Health.
5. *Pro Tip:* Shields also cap at 100. Don't let them go over!
*(Don't peek at the solution if you want to code it yourself first!)*
## Recap
* **Health** and **Shield** are separate bars. Health is your body; Shield is your buffer.
* **Variables** store values that change (like current HP). **Constants** stay the same (like healing speed).
* **Functions** are machines you use to get data (`GetHealth`) or change data (`SetHealth`).
* **Events** (`OnPlayerEnter`, `HealLoop`) are the triggers that make your code run at the right time.
You've just built a dynamic healing system. You're no longer just placing props; you're programming the rules of survival. Now go make some players sweat (or feel good).
## References
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-healing-items-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite/using-healing-items-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-healing-consumables-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite/using-items-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/fortnite-creative-glossary
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add using-healing-items-in-fortnite-creative 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.