segunda-feira, 29 de junho de 2026

UEFN Verse: NPC Spawner device

NPC stands for Non-Playable Character. NPCs are characters controlled by the game, including guards, villagers, wild animals, and many other types of characters.

UEFN includes specialized spawner devices for spawning standard characters, such as guards (Guard Spawner) and creatures (Wildlife Spawner). These devices provide many configuration options that are worth exploring, as they can handle a wide variety of use cases.

To customize NPC appearance and behavior, use the NPC Spawner device. It works together with two types of assets that enable the same appearance and behavior to be reused across multiple NPC Spawners:

  • NPC Character Definition: Defines the NPC's type, appearance, modifiers, and behavior.
  • NPC Behavior Script: Verse script that defines the NPC's behavior.


In the following articles, we will explore these two types of assets in greater detail.

The image below shows some of the properties of an NPC Spawner:


The Spawn Count field specifies how many NPCs spawned by this spawner can be active at the same time.

The NPC Character Definition must be selected. The NPC Behavior Script override field is optional because every NPC Character Definition is already associated with a Behavior Script. However, you can override it by assigning a different script in the NPC Spawner.

The Spawn On Timer property determines whether NPCs are spawned automatically by the NPC Spawner. When set to false, NPCs can only be spawned through Verse code.

The following properties expose the functions and events available in the NPC Spawner:


We will create a device that demonstrates how to control an NPC Spawner using Verse code. The Spawn Count property will be set to 1, ensuring that only one NPC is active at any given time.

The device runs a loop that spawns an NPC and waits for it to be eliminated. Each time an NPC is eliminated, the elimination counter is updated and displayed on the screen. The loop then starts again.

Open Verse Explorer, right-click on the project name, and select the option Add new Verse file to project.

In Device Name put npc_spawner_manager and click the Create Empty button.

Copy the Verse code below into the npc_spawner_manager file:

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

npc_spawner_manager := class(creative_device):

    @editable
    NpcSpawner : npc_spawner_device = npc_spawner_device{}

    var EliminatedCount : int = 0

    OnBegin<override>()<suspends>:void=

        loop:
            NpcSpawner.Spawn()
            NpcSpawner.EliminatedEvent.Await()

            set EliminatedCount += 1
            Print("Guards eliminated: {EliminatedCount}")
            Sleep(0.1)

The npc_spawner_manager device holds a reference to an npc_spawner_device. This reference is used to call the Spawn() function and wait for the EliminatedEvent to be triggered.

In this example, the npc_spawner_device is configured to allow only one active NPC at a time. Therefore, a Sleep(0.1) call is required to give the device time to update its internal state. Without this delay, Spawn() would not create a new NPC because the previously eliminated NPC would still be considered active internally.

Note: An infinite loop must contain at least one call to a <suspends> function, such as Sleep() or Await(), to yield control back to the engine. Otherwise, the engine will terminate the loop and a runtime error will be generated.


Save the file and compile the Verse code using the Verse > Compile Verse Code option from the UEFN menu.

Access the Content Drawer and add the npc_spawner_manager to the level.  We will need an NPC Spawner Device and an Item Spawner Device. The image below shows the elements that we will use in this example.



It will be necessary to create an NPC Character Definition to use with the NPC Spawner Device. We will create a very simple one. In the next article, we will take a closer look at the NPC Character Definition.

In the project folder in the Content Drawer, right-click on an empty space and select the Artificial Intelligence > NPC Character Definition option, as shown in the image.



Name it GuardRandomCharDef and double-click it to edit its properties. The NPC will be a Guard type and will use the default behavior. There is a list of modifiers used to define an NPC.

In the Team Modifier, change the Team Index to 2. This way, the NPCs will be on a different team from the player and will therefore attack them. In the Cosmetic Modifier, change the Character Look to Random Fortnite Character to add variety to the generated NPCs.


Select the NPC Spawner Device in the level. In the Details panel, change the NPC Character Definition to the new GuardRandomCharDef. Uncheck the Spawn On Timer property so that NPCs are spawned only through Verse code.


Select the npc_spawner_manager in the level. in the Details panel, select the reference to the NPC Spawner Device.  


We will provide a weapon for the player to defend against the NPCs. Select the Item Spawner in the level and add an element to the Item List. Choose some type of rifle.

Set Time Before First Spawn to 0 so that the weapon is available immediately at the start of the match.


We will provide infinite ammo for the player. In the Outliner panel, select Island Settings. In the Details panel, search for Infinite. Check the Infinite Magazine Ammo property. This property is located in the Inventory category.



Save the level and click the Launch Session button to load it in Fortnite. Eliminate the NPC so that a new NPC with a different appearance is generated.