Make Your NPCs Actually Walk: The Navigatable Interface
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.
Make Your NPCs Actually Walk: The Navigatable Interface
So, you've placed an NPC in your Fortnite island. It's standing there. It's looking at you. It's doing absolutely nothing but breathing heavily and judging your building skills. You want it to move, right? Not just a glitchy slide, but actual, purposeful movement—like a guard patrolling a base or a loot goblin running away from you.
In Verse, telling a character to move isn't as simple as dragging a path. You need to grab the "steering wheel" of their AI brain. That's what the Navigatable Interface is. Think of it as the remote control for any character's movement system. Once you have this remote, you can tell your NPC to walk to a specific spot, follow you, or guard a point. Let's stop making statues and start making chaos.
What You'll Learn
- What the Navigatable Interface is (and why you need it).
- How to get a reference to a character's movement system.
- How to tell an NPC to walk to a specific target.
- How to combine this with triggers to create interactive NPCs.
How It Works
Imagine you're trying to tell a friend to go to the kitchen. You can't just yell "GO!" into the void; you need to connect with them first. In Verse, characters (like NPCs or even players) have different "interfaces" or capabilities. One of those capabilities is Navigatable.
If a character has the Navigatable interface, it means the game engine trusts them to figure out how to get from Point A to Point B without walking into walls or falling off the map. It's like giving them a GPS.
Here is the catch: You don't just grab the GPS off the shelf. You have to ask the character for it. In programming terms, we call this casting or getting an interface. It's like asking a player, "Are you holding a shotgun?" If yes, you can tell them to shoot. If no, you can't. Similarly, you ask the character, "Do you have a Navigatable interface?" If yes, you can tell them to move.
The Scene Graph Connection
In the Unreal Engine scene graph, every object (Entity) is made of parts (Components). A FortCharacter (the standard Fortnite NPC) has many components: health, inventory, and Navigation. The GetNavigatable[] function is the tool that reaches into the character's component list and pulls out the navigation controller. Once you have that controller, you can send it commands like "Go to this position."
Let's Build It
We're going to build a simple "Loot Goblin Trap." You'll place a trigger zone. When a player walks in, a nearby NPC will stop doing nothing and run toward the player (or a specific spot) to "guard" the loot.
The Setup
- Place a Custom NPC (like a Guard or Wildlife type) in your level. Let's call it
Goblin. - Place a Trigger Volume (a box that detects players) near the Goblin.
- Create a new Verse file.
The Code
Copy this code into your Verse file. It's short, sweet, and gets the job done.
# We are creating a script that runs when the game starts.
# This script will hold our logic.
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Fortnite.com/AI }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Simulation }
# This is our main script structure.
# Think of it as the "Brain" of our island feature.
loot_goblin_behavior := class(creative_device):
# Wire these up in the UEFN Details panel by selecting your placed devices.
# Drag your NPC device into the first slot, your trigger into the second.
@editable
Goblin : npc_spawner_device = npc_spawner_device{}
@editable
Trigger : trigger_device = trigger_device{}
# This function runs once when the island loads.
OnBegin<override>()<suspends> : void =
# 4. CONNECT THE EVENT
# We want this code to run when someone enters the trigger.
# TriggeredEvent is the event that fires when a player activates the trigger.
Trigger.TriggeredEvent.Subscribe(OnTriggerActivated)
# This function is called when the trigger fires.
# 'Agent' is the player who walked in.
OnTriggerActivated(Agent : agent) : void =
# 1. FIND THE NPC
# GetAgents asks the spawner for the NPCs it spawned.
# We grab the first one if available, so we use an if-block.
Agents := Goblin.GetAgents()
if (GoblinAgent := Agents[0]):
# 2. GET THE NAVIGATABLE INTERFACE
# This is the magic line. We ask the goblin for its movement controller.
# If the goblin doesn't have navigation, this fails silently inside the if-block.
if (GoblinCharacter := GoblinAgent.GetFortCharacter[]):
if (GoblinNav := GoblinCharacter.GetNavigatable[]):
# 3. GET THE PLAYER'S POSITION
# Cast 'Agent' to a fort_character so we can call GetTransform().
if (PlayerCharacter := Agent.GetFortCharacter[]):
TargetPosition := PlayerCharacter.GetTransform().Translation
# Create a Navigation Target from that position.
# A Navigation Target is just a waypoint in the game world.
NavTarget := MakeNavigationTarget(TargetPosition)
# 5. TELL THE GOBLIN TO MOVE!
# NavigateTo is a suspends function, so we spawn a concurrent task for it.
# This lets the rest of the island keep running while the goblin walks.
spawn{ GoblinNav.NavigateTo(NavTarget) }
Print("Goblin has been dispatched!")```
### Walkthrough: What Just Happened?
1. **`Goblin.GetCurrentCharacter[]`**: Before we can drive the NPC, we need a reference to the character the spawner created at runtime. `GetCurrentCharacter[]` is a failable expression (note the `[]`) that hands us back that live character, or fails gracefully if the NPC hasn't spawned yet.
2. **`GoblinCharacter.GetNavigatable[]`**: This is the core concept. We didn't just say "Goblin move." We said, "Goblin, give me your navigation controller." This returns an object that has the power to issue movement commands.
3. **`MakeNavigationTarget(TargetPosition)`**: The game doesn't understand "Go there." It understands "Go to this specific coordinate in the 3D world." We wrapped the player's location in a `NavigationTarget` value using `MakeNavigationTarget`, which is like dropping a pin on the map.
4. **`spawn{ GoblinNav.NavigateTo(NavTarget) }`**: `NavigateTo` is a `<suspends>` function — it yields until the NPC arrives. Wrapping it in `spawn{}` creates an independent async task so the rest of your island logic doesn't stall while the goblin is walking.
## Try It Yourself
The code above makes the goblin run to the player. That's cool, but a bit one-dimensional.
**Challenge:** Modify the script so that instead of running to the player, the Goblin runs to a specific static point in the room (like a treasure chest location).
*Hint:* Instead of using `PlayerCharacter.GetTransform().Translation`, you can define a fixed `vector3` (a set of X, Y, Z coordinates) in your code, or add another `@editable` device property (like a `creative_prop`) and call `.GetTransform().Translation` on it to get its world position.
*Hint 2:* Look up how to get the location of a `Prop` or `Device` in Verse. It's similar to how we got the trigger!
## Recap
* **Navigatable Interface**: The "steering wheel" for an NPC's AI movement. You get it using `.GetNavigatable[]`.
* **Navigation Target**: A waypoint value that tells the AI *where* to go. You create one with `MakeNavigationTarget(position)`.
* **NavigateTo**: The `<suspends>` command that sends the NPC on its way — always call it inside `spawn{}` or another async context.
* **Always Check for None**: NPCs might not always have navigation (if they're broken or custom types), so using failable expressions inside `if` blocks prevents your code from crashing.
Now go make your NPCs useful. Or at least annoying. That's basically the same thing in Fortnite.
## References
- https://dev.epicgames.com/documentation/fortnite/verse-starter-07-final-result-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/fortnite/verse-starter-01-creating-the-npc-behavior-in-unreal-editor-for-fortnite
- https://dev.epicgames.com/documentation/en-us/fortnite/create-custom-npc-behavior-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/fortnite/create-your-own-npc-medic-in-unreal-editor-for-fortnite
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add Get the Navigatable Interface, this allows you to tell it to move. 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
- Get the Navigatable Interface, this allows you to tell it to move. ↗
- Get the Navigatable Interface, this allows you to tell it to move. ↗
- create-custom-npc-behavior-in-unreal-editor-for-fortnite ↗
- create-custom-npc-behavior-in-unreal-editor-for-fortnite ↗
- Get the navigatable interface of the character to set specific targets for the character to travel to. ↗
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.