# How do I get a UI Button in verse to communicate with a function passing an agent?

**URL:** <https://forums.unrealengine.com/t/how-do-i-get-a-ui-button-in-verse-to-communicate-with-a-function-passing-an-agent/2391569>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [March 15, 2025, 7:45pm UTC](https://forums.unrealengine.com/t/how-do-i-get-a-ui-button-in-verse-to-communicate-with-a-function-passing-an-agent/2391569 "2025-03-15T19:45:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tofuszn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tofuszn/32/1019707_2.png) [@Tofuszn](https://forums.unrealengine.com/u/Tofuszn)\
**Post date:** [March 15, 2025, 7:45pm UTC](https://forums.unrealengine.com/t/how-do-i-get-a-ui-button-in-verse-to-communicate-with-a-function-passing-an-agent/2391569/1 "2025-03-15T19:45:06Z")

</div>

how does one get an Agent from someone pressing a button in a custom UI? I’ve been working on some verse coding and am trying to increase a player’s health with persistence. I’ve been using a trigger to communicate between UI and the Function.

```auto
HealthBought(MaybeAgent:?agent):void=
        if(Agent:=MaybeAgent?, FortChar := Agent.GetFortCharacter[]):

```

That is what I have been attempting to do and that seems to temporarily work, but not save to persistence between sessions

---

<div class="post-metadata">

**Author:** ![eric.fruchter](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/eric.fruchter/32/1121256_2.png) [@eric.fruchter](https://forums.unrealengine.com/u/eric.fruchter)\
**Post date:** [March 18, 2025, 3:27pm UTC](https://forums.unrealengine.com/t/how-do-i-get-a-ui-button-in-verse-to-communicate-with-a-function-passing-an-agent/2391569/2 "2025-03-18T15:27:10Z")

</div>

Hello! It looks like there are potentially two issues you’re having, so let’s tackle them one at a time.

First, have you had a chance to review the persistence documentation and make sure you’re reading and writing to the weak\_map correctly? You can find that [here](https://dev.epicgames.com/documentation/en-us/uefn/using-persistable-data-in-verse).

Next, for the button callback handler:  
Here is a very minimal example of attaching a callback to a button in the world, and upping an integer that is stored in a persistent weak map. Hopefully this helps!

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

var MySavedPlayerData:weak_map(player, int) = map{}

hello_world_device := class(creative_device):

    @editable
    Button:button_device = button_device{}

    InteractedWithEventHandler(Agent:agent):void=
        if:
            Player := player[Agent]
            Player.IsActive[]
            Num := MySavedPlayerData[Player]
            set MySavedPlayerData[Player] = Num + 1
        then:
            Print("Num {Num}")

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

        for (Player : GetPlayspace().GetPlayers()):
            if:
                Player.IsActive[]
                not MySavedPlayerData[Player]
                set MySavedPlayerData[Player] = 0
    

        Button.InteractedWithEvent.Subscribe(InteractedWithEventHandler)

```

---

<div class="post-metadata">

**Author:** ![Mineblo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mineblo/32/1203575_2.png) [@Mineblo](https://forums.unrealengine.com/u/Mineblo)\
**Post date:** [March 18, 2025, 10:13pm UTC](https://forums.unrealengine.com/t/how-do-i-get-a-ui-button-in-verse-to-communicate-with-a-function-passing-an-agent/2391569/3 "2025-03-18T22:13:24Z")

</div>

Hey I understand this isn’t a full fletched out code but shouldn’t there be an `Player.IsActive[]` check before doing anything with player weak\_maps to prevent a verse runtime error?  
Was just wondering if its safe to not include it because button events should be instantaneous

---

<div class="post-metadata">

**Author:** ![eric.fruchter](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/eric.fruchter/32/1121256_2.png) [@eric.fruchter](https://forums.unrealengine.com/u/eric.fruchter)\
**Post date:** [March 18, 2025, 10:41pm UTC](https://forums.unrealengine.com/t/how-do-i-get-a-ui-button-in-verse-to-communicate-with-a-function-passing-an-agent/2391569/4 "2025-03-18T22:41:37Z")

</div>

Thank you! Added 😃

---

<div class="post-metadata">

**Author:** ![Tofuszn](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tofuszn/32/1019707_2.png) [@Tofuszn](https://forums.unrealengine.com/u/Tofuszn)\
**Post date:** [March 20, 2025, 5:40am UTC](https://forums.unrealengine.com/t/how-do-i-get-a-ui-button-in-verse-to-communicate-with-a-function-passing-an-agent/2391569/5 "2025-03-20T05:40:29Z")

</div>

Thank you so much!! This helped me a ton and I got my code working perfectly now 🙂
