The Magic Reset Button: Clearing Player Data in Fortnite
Tutorialbeginnercompiles

The Magic Reset Button: Clearing Player Data in Fortnite

Updated beginnerCode verified

The Magic Reset Button: Clearing Player Data in Fortnite

Have you ever played a game where your coins stayed with you forever? That is cool! But what if you want to start fresh? Maybe you want to test your island again. Or maybe you want to give every new player a clean slate. This tutorial shows you how to use Verse to reset player data. We will build a simple reset button. It will clear scores and items. It is like hitting the "New Game" button in a video game.

What You'll Learn

  • What persistent data is.
  • How to use a version number to track changes.
  • How to write a reset function in Verse.
  • How to clear data when a player joins.

How It Works

Think of your island like a big notebook. Every player has their own page in this notebook. This is called persistent data. The data stays there even if you close the game. It remembers their high score. It remembers their favorite color.

Sometimes, you want to erase that page. You want to start over. How do you know if the page is empty or full? You use a version number. Imagine a sticker on the notebook. If the sticker says "Version 1," the data is old. If it says "Version 2," the data is new.

We will write code that checks this sticker. If the sticker is missing or wrong, we wipe the page clean. We set the score to zero. We set the items to empty. This happens when a player joins. It is like a magic reset button.

Let's Build It

We will create a simple script. It will reset a player's score and items. We will use a module-scoped variable. This is a special box that stores data for all players. We call it a weak_map. It is like a shared locker room. Each player has their own locker.

Here is the code. Copy it into your Verse file.

# Import basic Verse tools
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# Define the shape of our player data
# This is like a template for the notebook page
player_data := struct:
    Score : int = 0        # Start with 0 points
    Items : []string = array{}  # Start with no items
    Version : int = 1      # The sticker version

# A device class that manages player data resets.
# Place one instance of this device on your island.
player_reset_manager := class(creative_device):

    # This is our shared locker room (weak_map)
    # It holds data for every player who joins
    # note: weak_map keys on player identity; data is cleared if the player leaves.
    var PlayerLockers : weak_map(player, player_data) = map{}

    # Called automatically by UEFN when the device starts
    OnBegin<override>()<suspends> : void =
        # Subscribe to the player-joined event for this session
        GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerJoined)

    # This function resets a player's data
    # Think of it as erasing the notebook page
    ResetPlayerData(P : player) : void =
        # Create a fresh, empty data template
        FreshData := player_data{}
        # Put the fresh data into the player's locker
        # This overwrites any old data
        if (set PlayerLockers[P] = FreshData) {}

    # This event runs when a player joins the island
    OnPlayerJoined(P : player) : void =
        # Check if the player already has a locker
        if (CurrentData := PlayerLockers[P]):
            # Locker exists. Check the version sticker.
            # If the version is old (0), reset the data.
            # We use 0 to mean "no version set yet."
            if (CurrentData.Version = 0):
                ResetPlayerData(P)
        else:
            # No locker exists. Create one with default data.
            if (set PlayerLockers[P] = player_data{}) {}

Walkthrough

  1. The Template: We define player_data. It has a score, a list of items, and a version. This is the structure of our notebook page.
  2. The Locker Room: We create PlayerLockers. This is a weak_map. It connects a player to their data.
  3. The Reset Function: ResetPlayerData creates fresh data. It sets the score to zero. It sets the version to one. It puts this fresh data into the player's locker.
  4. The Join Event: OnPlayerJoined runs when a player arrives. It checks if they have a locker. If not, it makes one. If yes, it checks the version. If the version is zero, it resets the data.

Try It Yourself

Now it is your turn to play!

  1. Create a new Verse script in UEFN.
  2. Paste the code above.
  3. Add a Trigger Volume device to your island.
  4. Add a Text Label device to show the score.
  5. Try to modify the ResetPlayerData function. Can you add a Coin item to the list when they reset?
  6. Test your island. Join the game. See if the score starts at zero.

Hint: Look at the player_data struct. You can add new lines to it. Just make sure to update the reset function too!

Recap

You learned how to reset player data in Fortnite. You used a weak_map to store player info. You used a version number to track changes. You wrote a function to clear that data. Now you can start fresh anytime!

References

  • https://dev.epicgames.com/documentation/en-us/fortnite/using-persistable-data-in-verse
  • https://dev.epicgames.com/documentation/en-us/uefn/using-persistable-data-in-verse
  • https://dev.epicgames.com/documentation/en-us/fortnite/make-your-own-ingame-leaderboard-in-verse
  • https://dev.epicgames.com/documentation/en-us/uefn/make-your-own-in-game-leaderboard-in-verse
  • https://dev.epicgames.com/documentation/en-us/fortnite/persistence-devices-in-unreal-editor-for-fortnite

Verse source files

Check your understanding

Test yourself with an interactive quiz and track your progress + earn XP — free for members.

Turn this into a guided course

Add Resetting Persistable Data for Your Island 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.

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.

Comments

    Sign in to vote, comment, or suggest an edit.Sign in