# Guide to Event Subscribing with Additional Parameters (Handler Functions)

**URL:** <https://forums.unrealengine.com/t/guide-to-event-subscribing-with-additional-parameters-handler-functions/793925>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite\
**Created:** [March 19, 2023, 3:07am UTC](https://forums.unrealengine.com/t/guide-to-event-subscribing-with-additional-parameters-handler-functions/793925 "2023-03-19T03:07:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrendannnD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BrendannnD](https://forums.unrealengine.com/u/BrendannnD)\
**Post date:** [March 19, 2023, 3:07am UTC](https://forums.unrealengine.com/t/guide-to-event-subscribing-with-additional-parameters-handler-functions/793925/1 "2023-03-19T03:07:49Z")

</div>

It seems like a common problem creators run into while learning Verse is trying to pass in additional parameters while subscribing events to functions. For example, if you have multiple buttons that you want to print a different color based on a **string** parameter, you might try subscribing the **InteractedWithEvent** to a function like **PrintColor(Color : string)**. This would cause an error, because (generally) by default all events can only be subscribed to a function with an **agent** parameter. The solution to this is a handler function.

Handler functions are essentially a way of passing additional parameters by creating a class object and calling a function using the class attributes. Here is a copy-paste format for how to use them:

**Paste this at the very top of your code (or above your main class)**:

```auto
Handler1 := class() {
    Device : main <#YOU MUST CHANGE "main" TO YOUR VERSE DEVICE NAME#>
    Parameter1 : int <#Change "int" to your parameter type, ex: float, string#>

    HandlerFunction(Agent : agent) : void = {
        Device.MainFunction(Parameter1)
    }
}

```

**Paste this into your OnBegin**. You will need to change the Button.InteractedWithEvent to whatever event you are subscribing with. You will also need to change Value to whatever value you want passed through the parameter:

```auto
Button.InteractedWithEvent.Subscribe(Handler1{Device:=Self, Parameter1:=Value}.HandlerFunction)

```

**Finally, create your main function** (inside main class but outside of OnBegin):

```auto
MainFunction(Parameter1 : int) : void = {
        Print("{Parameter1}") #Function code here
    }

```

The uses of handlers may not seem immediately obvious, but they can be very useful when you have multiple devices with the same functionality but different inputs, like if you had an array of buttons each designated to increase the score of a different score manager. I hope this was helpful and good luck!

---

<div class="post-metadata">

**Author:** ![VysenaWoyka](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vysenawoyka/32/1003669_2.png) [@VysenaWoyka](https://forums.unrealengine.com/u/VysenaWoyka)\
**Post date:** [March 19, 2023, 3:15am UTC](https://forums.unrealengine.com/t/guide-to-event-subscribing-with-additional-parameters-handler-functions/793925/2 "2023-03-19T03:15:37Z")

</div>

This indeed helped me a lot when I knew about this. Thanks for the tutorial, I’m sure it’s gonna help a lot of people!

---

<div class="post-metadata">

**Author:** ![Cleverlike\_Studios](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/cleverlike_studios/32/1216891_2.png) [@Cleverlike\_Studios](https://forums.unrealengine.com/u/Cleverlike_Studios)\
**Post date:** [March 19, 2023, 5:43pm UTC](https://forums.unrealengine.com/t/guide-to-event-subscribing-with-additional-parameters-handler-functions/793925/3 "2023-03-19T17:43:20Z")

</div>

Thank you! I’ll be using this for sure.

---

<div class="post-metadata">

**Author:** ![DiG3](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dig3/32/1036114_2.png) [@DiG3](https://forums.unrealengine.com/u/DiG3)\
**Post date:** [March 20, 2023, 7:09pm UTC](https://forums.unrealengine.com/t/guide-to-event-subscribing-with-additional-parameters-handler-functions/793925/4 "2023-03-20T19:09:02Z")

</div>

Thanks for posting @BrendannnD.

We also use this pattern in the [Tagged Lights Puzzle Tutorial](https://dev.epicgames.com/documentation/en-us/uefn/tagged-lights-4-toggling-lights-with-buttons-in-verse#connectingbuttonpressestotogglinglights).  
For example, the button handler looks like:

```auto
 button_event_handler := class():
 # Positions used to access the lights this button controls.
 Indices : []int

 # tagged_lights_puzzle that created this button_event_handler so we can call functions on it.
 PuzzleDevice : tagged_lights_puzzle
    
 OnButtonPressed(Player : agent) : void =
     # Tell the PuzzleDevice to toggle the lights at the positions this button controls.
     PuzzleDevice.ToggleLights(Indices)

```

---

<div class="post-metadata">

**Author:** ![K-MUS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@K-MUS](https://forums.unrealengine.com/u/K-MUS)\
**Post date:** [April 24, 2023, 1:30pm UTC](https://forums.unrealengine.com/t/guide-to-event-subscribing-with-additional-parameters-handler-functions/793925/5 "2023-04-24T13:30:37Z")

</div>

Hi, @BrendannnD

What about adding the effect suspends ?

I need to use .await inside the “MainFunction”. Because I need to use a Countdown. Followed the tutorial for this

So I added but I end up with an error, that idk how to resolve. In line:

```auto
Zone.AreaIsScoredEvent.Subscribe(HandlerAreaIsScoredEvent{Device:=Self, Zone:=I}.HandlerFunction)

```

My code

```auto

var CountdownTimer : countdown_timer = countdown_timer{}
InitialCountdownTime : float = 30.0  

HandlerAreaIsScoredEvent:= class() {
    Device : Conquest   
    Zone : int  

    HandlerFunction(Agent : agent)<suspends> : void = {
        Device.MainFunction(Agent, Zone)
    }
}

OnBegin<override>()<suspends>:void=
  for( I->Zone: Zones):
    Zone.AreaIsScoredEvent.Subscribe(HandlerAreaIsScoredEvent{Device:=Self, Zone:=I}.HandlerFunction)

MainFunction(Agent: agent, Zone : int)<suspends> : void = {
  StartCountdown()

StartCountdown()<suspends>: void =
  Print("Starting countdown")
        
  AllPlayers:[]player = GetPlayspace().GetPlayers()
    for(Player:AllPlayers):
      if(PlayerUI := GetPlayerUI[Player]):
        set CountdownTimer = countdown_timer{MaybePlayerUI := option{PlayerUI}, RemainingTime := InitialCountdownTime}
        CountdownTimer.StartCountdown()
        CountdownTimer.CountdownEndedEvent.Await()

```

---

<div class="post-metadata">

**Author:** ![BrendannnD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BrendannnD](https://forums.unrealengine.com/u/BrendannnD)\
**Post date:** [April 25, 2023, 12:22am UTC](https://forums.unrealengine.com/t/guide-to-event-subscribing-with-additional-parameters-handler-functions/793925/6 "2023-04-25T00:22:44Z")

</div>

Hi, here you would want to do in the HandlerFunction:

```auto
spawn{Device.MainFunction(Agent, Zone)}

```

---

<div class="post-metadata">

**Author:** ![MattRix](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mattrix/32/686548_2.png) [@MattRix](https://forums.unrealengine.com/u/MattRix)\
**Post date:** [May 5, 2023, 5:08am UTC](https://forums.unrealengine.com/t/guide-to-event-subscribing-with-additional-parameters-handler-functions/793925/7 "2023-05-05T05:08:51Z")

</div>

I posted a slightly different approach to this problem here: [Wrapping Subscribe() to pass additional data to listeners | Uefn Code Snippet](https://dev.epicgames.com/community/snippets/d8k/fortnite-wrapping-subscribe-to-pass-additional-data-to-listeners)

My approach is that I’m creating the handler in an extension method, so you can just say `MyButton.InteractedWithEvent.SubscribeAgent(MyFunc, "some extra data")`

---

<div class="post-metadata">

**Author:** ![BrendannnD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BrendannnD](https://forums.unrealengine.com/u/BrendannnD)\
**Post date:** [May 7, 2023, 5:55am UTC](https://forums.unrealengine.com/t/guide-to-event-subscribing-with-additional-parameters-handler-functions/793925/8 "2023-05-07T05:55:27Z")

</div>

Great approach! Might have to try this instead, I like the simpler syntax.

---

<div class="post-metadata">

**Author:** ![mysakcreative](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mysakcreative](https://forums.unrealengine.com/u/mysakcreative)\
**Post date:** [August 9, 2025, 1:02pm UTC](https://forums.unrealengine.com/t/guide-to-event-subscribing-with-additional-parameters-handler-functions/793925/10 "2025-08-09T13:02:41Z")

</div>

Thank you so much! This is very useful! 😀
