# listenable Interfaces/Functions Should Pass this as the First Argument

**URL:** <https://forums.unrealengine.com/t/listenable-interfaces-functions-should-pass-this-as-the-first-argument/1206712>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [June 21, 2023, 9:42pm UTC](https://forums.unrealengine.com/t/listenable-interfaces-functions-should-pass-this-as-the-first-argument/1206712 "2023-06-21T21:42:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyperdr1ve](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@hyperdr1ve](https://forums.unrealengine.com/u/hyperdr1ve)\
**Post date:** [June 21, 2023, 9:42pm UTC](https://forums.unrealengine.com/t/listenable-interfaces-functions-should-pass-this-as-the-first-argument/1206712/1 "2023-06-21T21:42:46Z")

</div>

Trying to use `listenable`s to create device interactions that are not 1:1 (1 device directly bound to another device) is extremely painful right now.

For instance, let’s say you want to monitor the 40 vehicle spawners in your level to respawn a vehicle whenever a player exits a vehicle.

`AgentExitsVehicleEvent` tells you when an agent exits the vehicle, but it doesn’t give you the `vehicle_spawner_device` that called the event. So now you have to write your own little tracking system to map vehicle spawners to players😩

This is the same situation for literally every device in the game e.g.:

- Vending machines/ItemSpawnedEvent
- trigger\_device/TriggeredEvent
- trick\_tile\_device/ActivatedEvent
- tracker\_device/CompleteEvent
- timer\_device/SuccessEvent

This was the same situation back when UE4’s Hit/Overlap events didn’t return the primitive component and actor that was firing the event. Luckily this was remedied. We need a similar standard for fortnite listenables, where perhaps the first argument is always `this` 🙏

---

<div class="post-metadata">

**Author:** ![DustinREDGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dustinredgames/32/634988_2.png) [@DustinREDGames](https://forums.unrealengine.com/u/DustinREDGames)\
**Post date:** [June 21, 2023, 9:57pm UTC](https://forums.unrealengine.com/t/listenable-interfaces-functions-should-pass-this-as-the-first-argument/1206712/2 "2023-06-21T21:57:26Z")

</div>

I agree more info passed would be extremally helpful. But for now, you can create a callback handler class that passes the additional references you need to what device triggered the event. Something like this: (untested!)

```auto
# custom callback handler that passes the device that triggered the event
CustomCallbackHandler := class():
    Manager : test_callback_device 
    Device : vehicle_spawner_device
    HandlerFunction(Agent:agent):void=
        Manager.OnEventTriggered(Agent, Device)

test_callback_device := class(creative_device):

    @editable
    Devices : []vehicle_spawner_device = array{}

    OnBegin<override>()<suspends>:void=
        for(X -> Device : Devices):
            # pass reference to callback 
Device.AgentExitsVehicleEvent.Subscribe(CustomCallbackHandler{Manager:=Self, Device:=Device}.HandlerFunction)

    OnEventTriggered(Agent:agent, Device:vehicle_spawner_device):void=
        # do something....

```

---

<div class="post-metadata">

**Author:** ![hyperdr1ve](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@hyperdr1ve](https://forums.unrealengine.com/u/hyperdr1ve)\
**Post date:** [June 21, 2023, 10:29pm UTC](https://forums.unrealengine.com/t/listenable-interfaces-functions-should-pass-this-as-the-first-argument/1206712/3 "2023-06-21T22:29:05Z")

</div>

wooooooowww, thank you for this!

> [@DustinREDGames](#):
>
> `CustomCallbackHandler{Manager:=Self, Device:=Device}.HandlerFunction`

🤯 I had no idea you could construct a class, initialize its members and return a pointer to the instantiated class function all in one blow. This expanded my mind and made my implementation trivial.

> [@DustinREDGames](#):
>
> `for(X -> Device : Devices):`

What is the advantage of this syntax? The X seems unused. Force of habit for more complex loops?

---

<div class="post-metadata">

**Author:** ![DustinREDGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dustinredgames/32/634988_2.png) [@DustinREDGames](https://forums.unrealengine.com/u/DustinREDGames)\
**Post date:** [June 22, 2023, 2:09pm UTC](https://forums.unrealengine.com/t/listenable-interfaces-functions-should-pass-this-as-the-first-argument/1206712/4 "2023-06-22T14:09:14Z")

</div>

The X gives you the index in the loop, but yes unused in this example, just out of habit. 😉
