Stop Guessing, Start Knowing: How to Check Player Health with Fortnite APIs
Stop Guessing, Start Knowing: How to Check Player Health with Fortnite APIs
Imagine you’re building a chaotic Battle Royale island. You want a trap that only triggers when a player is already hurt, or a healer that only works if someone is below 50 HP. How does your code know how much health a player has? You don’t guess. You ask the game.
In Verse, we don’t write magic spells from thin air. We use modules (think of them as pre-made cheat sheets or rulebooks) to talk to the Fortnite API. The API is like the game’s central nervous system—it knows everything: who is alive, what they’re holding, and how much damage they’ve taken. This tutorial teaches you how to import these "cheat sheets" so your code can peek into the game state and react accordingly.
What You'll Learn
- Modules: What they are and why you can’t build a house without bricks.
- Imports: How to bring Fortnite’s built-in tools into your custom device.
- API Calls: How to ask the game for a player’s current health using the
Playermodule. - Scene Graph Basics: Understanding that every player is an "Entity" in the game world.
How It Works
The "Module" Analogy: Your Loadout
In Fortnite, you don’t start with a Legendary rifle and a shield potion. You start with nothing and pick up items from the ground. In Verse, modules are those items.
A module is a file containing code that Epic Games wrote for you. It contains definitions for things like Player, Game, World, and Vector. You can’t just shout "HEALTH!" at the computer and expect it to work. You have to import the module that defines what a Player is.
Think of a module like a Loot Pool. If you want to use a specific item (like checking health), you first have to declare that you’re pulling from that specific pool.
The "Import" Statement: Opening the Chest
In Verse, you don’t "include" files like you might in C++. You import them. This is like walking up to a loot chest and pressing 'E' to take the contents into your inventory.
// This line says: "Hey Verse, I need the rules for Players."
import Players from "Fortnite.com"
If you forget this line, Verse will look at your code, see you trying to use Player, and say, "I don't know what that is. Did you forget to loot the chest?" Then it throws a compiler error.
The Scene Graph: Entities and Components
This is the most important concept for UE6 and Verse. The game world isn’t just a list of numbers; it’s a hierarchy of Entities.
- Entity: A physical object in the world (a player, a car, a building piece).
- Component: A trait or ability attached to that entity (Health, Inventory, Movement).
When you want to check a player's health, you are accessing a Component (Health) attached to an Entity (Player). The Player module gives you the tools to interact with that specific entity.
Let's Build It
We are going to build a simple Health Monitor Device. When a player steps on a trigger, it will print their current health to the debug console. This isn’t a full game, but it’s the foundation for any health-based mechanic (healers, traps, scoring).
Step 1: Create the Verse File
- In UEFN, open your project.
- Go to Verse > Verse Explorer.
- Right-click your project name and select Add new Verse file to project.
- Name it
health_checker.verse. - Double-click it to open in Visual Studio Code.
Step 2: The Code
Copy and paste this code. It’s short, but every line matters.
Walkthrough: What Just Happened?
import Players from "Fortnite.com": This is the most critical line. We are telling Verse, "I want to use the code related to Players." The string"Fortnite.com"is the path to the module. It’s like saying "Go to the Fortnite server and grab the Player rulebook."struct HealthChecker : WorldDevice: We are creating a new type of device.WorldDevicemeans this code runs in the game world, not just in a menu.GetPlayerHealth(player: Players.Player) : int32: This is a function. It’s a machine. You put aPlayerentity into one side, and it spits out anint32(a 32-bit integer, which is just a whole number like 100, 50, or 0).player.GetHealth(): This is the API call. The.(dot) operator is how you access components. You are saying, "Heyplayerentity, give me yourHealthcomponent's current value."
Step 3: Build and Test
- Save the file in VS Code.
- Go back to UEFN.
- Click Verse > Build Verse Code.
- If you see a green checkmark, you’re good. If you see a red stop sign, check for typos. Did you misspell
Players? Did you forget the semicolon?
Try It Yourself
The code above defines how to get health, but it doesn’t do anything yet. Your challenge:
Create a Trigger Device that prints a player's health when they step on it.
Hint 1: You’ll need to use a Trigger device in UEFN.
Hint 2: In Verse, you can connect a Trigger’s OnBeginOverlap event to your code.
Hint 3: You’ll need to pass the Player entity from the overlap event into your GetPlayerHealth function.
Don't worry if you get stuck! The next tutorial will cover connecting devices to Verse events. For now, just make sure your import line is there and your function compiles.
Recap
- Modules are pre-written code libraries (like loot pools) that you must import to use.
- Imports bring definitions into your file so Verse knows what
Player,Game, etc., mean. - The Dot (
.) Operator is how you access components (like Health) on an Entity (like a Player). - API Calls like
GetHealth()are questions you ask the game engine for real-time data.
References
- https://dev.epicgames.com/documentation/en-us/fortnite/programming-with-verse-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/modify-and-run-your-first-verse-program-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/create-custom-npc-behavior-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/uefn/verse-language-reference
- https://dev.epicgames.com/documentation/en-us/uefn/learn-programming-with-verse-in-unreal-editor-for-fortnite
Get the complete code — free
You've read the full walkthrough. The complete, copy-paste-ready Verse solution is free for members — sign in to unlock it.
Free with your BrainDead.TV / BrainDeadGuild Discord account. The walkthrough above is always free.
Verse source files
- 01-fragment.verse · fragment
- 02-fragment.verse · fragment
Turn this into a guided course
Add How to use Fortnite API (module declarations) in Verse (UEFN) 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.