# Session Variable, works in my editor session, not for my published maps?

**URL:** <https://forums.unrealengine.com/t/session-variable-works-in-my-editor-session-not-for-my-published-maps/1313650>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [September 27, 2023, 3:33am UTC](https://forums.unrealengine.com/t/session-variable-works-in-my-editor-session-not-for-my-published-maps/1313650 "2023-09-27T03:33:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LoPing](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/loping/32/737300_2.png) [@LoPing](https://forums.unrealengine.com/u/LoPing)\
**Post date:** [September 27, 2023, 3:33am UTC](https://forums.unrealengine.com/t/session-variable-works-in-my-editor-session-not-for-my-published-maps/1313650/1 "2023-09-27T03:33:10Z")

</div>

My code is almost the exact same as Epic’s sample and works in sessions originating from UEFN perfectly.

```auto
# defined globally outside of any classes
var RoundNumber:weak_map(session, int) = map{}
var BestCompletionTime:weak_map(session, float) = map{}
...
# defined inside my creative_device class
    var ThisRound: int = 1
    var TimeToBeat: float = 60.0
...
# code in my creative device called from 'OnBegin'
IncrementRound():void=
        set ThisRound = if (LastRound := RoundNumber[GetSession()]) then LastRound + 1 else 1
        if:
            set RoundNumber[GetSession()] = ThisRound
        set TimeToBeat = if (BestTime := BestCompletionTime[GetSession()]) then BestTime else 60.0
...
# BestCompletionTime set later in the same creative_device
      set BestCompletionTime[GetSession()] = HUDupdate.LastKillTime
```

When I launch a session from UEFN, the two session variables: ‘ThisRound’ (the int round-number) and ‘BestTime’ (a float representing the best-completion-time-to-date) work exactly as expected. The game ends, and when I hit “play” again, I keep all my session values. Perfection.

When I publish a private version and play a round in Fortnite, then hit “[R] Ready Up” to play again, there is no memory of my session variables. Both global variables are their default, round-one values for every game. And, I am not returning to the Lobby, I know everything will be lost then.

Anyone get their session variables working? The **RoundNumber** is an exact duplicate of Epic’s code with just variable name changes.

PS1 – I did my homework, I re-read Epic’s documentation on Global Variables and Weak Maps  
PS2 – Do you have to restart games by some other way than using the built-in ‘Ready Up’?

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [September 28, 2023, 11:08am UTC](https://forums.unrealengine.com/t/session-variable-works-in-my-editor-session-not-for-my-published-maps/1313650/2 "2023-09-28T11:08:43Z")

</div>

`weak_maps` are supposed to store variable during a single round, not between games or rounds. See [session class](https://dev.epicgames.com/documentation/en-us/uefn/verse-api/versedotorg/simulation/session) “Type for which there is a single instance per round”  
The docs say it could change in the future to one instance per game

> [@LoPing](#):
>
> The game ends, and when I hit “play” again, I keep all my session values. Perfection.

This is actually a bug, see [Verse Internal Error - #4 by im\_a\_lama](https://forums.unrealengine.com/t/verse-internal-error/1300779/4)

So I’m not sure what you’re trying to do exactly, but maybe using a custom round system instead would work better, if I understood correctly 👍

SEE: [Verse global variables no longer working, even on previous uploads](https://forums.unrealengine.com/t/verse-global-variables-no-longer-working-even-on-previous-uploads/1292404)  
EDIT: I’m not sure about the fact that it resets between rounds, maybe someone can help me with that  
EDIT2: If that’s the case, this is something they reverted, it used to work between rounds but not anymore, this is why the “official” sample is not working.

---

<div class="post-metadata">

**Author:** ![LoPing](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/loping/32/737300_2.png) [@LoPing](https://forums.unrealengine.com/u/LoPing)\
**Post date:** [September 28, 2023, 5:09pm UTC](https://forums.unrealengine.com/t/session-variable-works-in-my-editor-session-not-for-my-published-maps/1313650/3 "2023-09-28T17:09:27Z")

</div>

Thanks, a lot of people are in my boat. I missed the big flurry of developers noticing the retraction of ‘GetSession()’ two weeks ago, so I ended up doing a lot of wasted work and making posts redundant to theirs.
