# Lost Data When Updating PlayerProfileDataMap Multiple Times in One Flow - How to Avoid It

**URL:** <https://forums.unrealengine.com/t/lost-data-when-updating-playerprofiledatamap-multiple-times-in-one-flow-how-to-avoid-it/2583199>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, bug-report, fortnite\
**Created:** [June 28, 2025, 2:16pm UTC](https://forums.unrealengine.com/t/lost-data-when-updating-playerprofiledatamap-multiple-times-in-one-flow-how-to-avoid-it/2583199 "2025-06-28T14:16:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dudiing](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dudiing/32/716892_2.png) [@Dudiing](https://forums.unrealengine.com/u/Dudiing)\
**Post date:** [June 28, 2025, 2:16pm UTC](https://forums.unrealengine.com/t/lost-data-when-updating-playerprofiledatamap-multiple-times-in-one-flow-how-to-avoid-it/2583199/1 "2025-06-28T14:16:23Z")

</div>

# ⚠ Lost Data When Updating `PlayerProfileDataMap` Twice in One Flow

Hey creators! 👋

I wanted to share a subtle bug I ran into while using persistent `weak_map` data like `PlayerProfileDataMap`. If you modify a player’s data and then later update it again using the same base data, **you can accidentally overwrite earlier changes, even from other functions.** The key point is: **only the last update you make will persist** ; any previous ones will be lost.

* * *

### 🧠 The Problem

Let’s say you have this:

```auto
var PlayerProfileDataMap:weak_map(player, player_profile_data) = map{}

```

And this function to add score:

```auto
AddScore(Player:player, Amount:int):void = 
    if (Data := PlayerProfileDataMap[Player]):
        set PlayerProfileDataMap[Player] = player_profile_data:
            MakePlayerProfileData<constructor>(Data)
            Score := Data.Score + Amount

```

Then in another function:

```auto
HandleButtonPress(Player:player):void =
    if (Data := PlayerProfileDataMap[Player]):
        AddScore(Player, 100) # <-- Problem here
        if:
            set PlayerProfileDataMap[Player] = player_profile_data:
                MakePlayerProfileData<constructor>(Data)
                Level := Data.Level + 1

```

🔴 **What happens:**  
`AddScore` writes an updated score into the map, but immediately after, the second `set` uses the **same original `Data`** , overwriting the map with stale information. This means the score increase is lost, because **only the last `set` call’s data is saved**.

* * *

### ✅ The Solutions

You don’t need to rewrite or merge the data manually. Just make sure the `AddScore` call happens **after** the last overwrite, or **outside/before** any conditional assignment using `Data`.

#### Option 1: Move the call after the `set`

```auto
HandleButtonPress(Player:player):void =
    if (Data := PlayerProfileDataMap[Player]):
        if:
            set PlayerProfileDataMap[Player] = player_profile_data:
                MakePlayerProfileData<constructor>(Data)
                Level := Data.Level + 1
        AddScore(Player, 100) # ✅ Now this change won't be overwritten

```

#### Or Option 2: Move the call outside the `Data` scope

```auto
HandleButtonPress(Player:player):void =
    AddScore(Player, 100) # ✅ Now this change won't be overwritten
    if (Data := PlayerProfileDataMap[Player]):
        if:
            set PlayerProfileDataMap[Player] = player_profile_data:
                MakePlayerProfileData<constructor>(Data)
                Level := Data.Level + 1

```

* * *

### 💡 Key takeaway

- When you modify `PlayerProfileDataMap` multiple times in a single logical flow, **only the last update will be saved**.
- Earlier updates done with a stale reference will be overwritten and lost.
- To prevent losing data, **make sure function calls that update persistent data occur after all other writes** , or outside the `Data` conditional block.

I hope this helps someone avoid this tricky problem that took me hours to figure out on my map! 😅
