Versioning and Resetting Save Data
In this lesson you'll learn to
- βStudent can version-migrate and reset persistable data safely when the save schema changes between island updates.
Student can version-migrate and reset persistable data safely when the save schema changes between island updates.
π Reference & full walkthrough: Versioning and Resetting Save Data
π Builds on: lesson 8 volcano_save class
π§© Your capstone piece: Save-schema migration so shipped Volcano Survival updates don't corrupt player banks
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
- 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. - The Locker Room: We create
PlayerLockers. This is aweak_map. It connects a player to their data. - The Reset Function:
ResetPlayerDatacreates fresh data. It sets the score to zero. It sets the version to one. It puts this fresh data into the player's locker. - The Join Event:
OnPlayerJoinedruns 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!
- Create a new Verse script in UEFN.
- Paste the code above.
- Add a Trigger Volume device to your island.
- Add a Text Label device to show the score.
- Try to modify the
ResetPlayerDatafunction. Can you add a Coin item to the list when they reset? - 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
Keep going β free
You've read the intro. The rest of this lesson is free for members. Sign in to continue and track your progress.
Sign in free to continue this lessonSources
/guides/resetting-persistable-data-for-your-islandBiloxi Studios original lesson
Add this lesson to your free study plan.
π§ The Keeperβs log
Quest complete? Chart your next heading from the π East Volcano expedition.
β΅ Take me there