domingo, 15 de fevereiro de 2026

UEFN Verse: Introduction to Persistence

In this article I will present the basics of using persistence in UEFN using Verse.

First, let's clarify what we mean by persistence. On a standard Fortnite island, when a player leaves the experience, their experience-related data, such as points or collected items, is lost.

The use of persistence allows some data associated with the player to be saved in the experience. When the player returns to the experience, this data can be retrieved, allowing the player to continue from where they left off.

To persist player data, you need to create a global variable of type weak_map using the player type as the key. A weak map is a type of map that does not allow listing its elements for iteration. The only way to access an element of a weak map is by using its index. If you don't know what a map is, I suggest reading my article:

UEFN Verse: Map

The line below shows how to create a weak_map variable named PlayerData that uses the player type as the key and the float type as the value. This variable declaration needs to be outside of a class for it to be global.

var PlayerData:weak_map(player, float) = map{}

To make the use of persistence clear, let's start with a simple example using a Timer Device and a Button Device. The Timer Device will be configured to count upwards. When the player presses the button, the current Timer value will be saved. When the player re-enters the experience, the timer value will be retrieved and assigned to the timer so that it doesn't start counting from zero again.

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

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

Copy the Verse code below into the persistence_device file:

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

var PlayerData:weak_map(player, float) = map{}

persistence_device := class(creative_device):

    @editable  
    TimerDevice: timer_device = timer_device{} 
    # The timer needs to count upwards.
	
    @editable
    SaveButton : button_device = button_device{}

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

        SaveButton.InteractedWithEvent.Subscribe(ButtonPressed)

        if:   # Retrieves saved data if it exists.
            Player := GetPlayspace().GetPlayers()[0]
            TimeElapsed := PlayerData[Player]
        then:
            TimerDevice.SetActiveDuration(TimeElapsed, Player)

    ButtonPressed(Agent:agent):void=	
        if: 
            Player := player[Agent]
            set PlayerData[Player] = TimerDevice.GetActiveDuration(Agent)
        then:
            Print("Data saved.")

The OnBegin function registers the ButtonPressed function in the InteractedWithEvent event of the SaveButton and checks if a value has been saved for the current player by accessing the weak_map with the PlayerData[Player] expression.

The ButtonPressed function retrieves the current count from the Timer Device using the GetActiveDuration function and saves it to the weak_map using the current player as the key.

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

Access the Content Drawer and add the persistence_device to the level. Add a Timer Device and a Button Device and place them close to each other.



Select the Timer Device at the level. In the Details tab, select CountUp under Count Down Direction. Set a high value for Duration. In my example, I used 600 seconds (10 minutes). Check the Start at Game Start option.


Select the persistence_device at the level. In the Details tab, add the Timer Device and Button Device references.



Save the level and click the Launch Session button to load the level in Fortnite. Wait a few seconds in-game and then use your character to press the button in the level. When the button is pressed, the current timer value will be persisted.


To simulate local persistence, do not end your UEFN session. In Fortnite, press ESC to exit the current experience without exiting your UEFN session.


When you re-enter the experience with the same player, the Timer Device will start counting from the saved value.

In the next article, I will discuss some more concepts of persistence and show how it is generally used in the experiences.

Just a word of caution. Avoid experimenting with persistence on published islands. This topic requires careful planning to prevent future changes to the save variables from causing players to lose their data.

Table of Contents Verse