# How do you implement your own listenable in Verse?

**URL:** <https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [March 29, 2023, 3:13pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267 "2023-03-29T15:13:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![spentak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spentak/32/642372_2.png) [@spentak](https://forums.unrealengine.com/u/spentak)\
**Post date:** [March 29, 2023, 3:13pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/1 "2023-03-29T15:13:18Z")

</div>

I can’t figure out how to implement my own listenable function (Can’t find a code sample on this)

Basically I have a timer and on each loop iteration I want to call OnTimerIteration so anyone who is subscribed can get notified.

I’ve tried every syntax combination I can think of based on the cryptic Verse.digest notes with no luck.

```auto
counter := class():
    TimerTickPeriod : float
    var RemainingTime<private> : float = 1.0
    CountdownStartedEvent : event() = event(){}
    CoundownEndedEvent : event() = event(){}
    OnTimerIteration<public> : listenable() # <-- The object one would .Subscribe to
    StartTimer<public>(TotalTime : float): void=
        set RemainingTime = TotalTime
        spawn:
            RunCountdown()
    RunCountdown<private>()<suspends> : void=
        CountdownStartedEvent.Signal()
        loop:
            Sleep(TimerTickPeriod)
            OnTimerIteration() # <-- Let my subscribers know
            set RemainingTime -= TimerTickPeriod
            if (RemainingTime <= 0.0):
                CoundownEndedEvent.Signal()
                break

```

---

<div class="post-metadata">

**Author:** ![FoggyDude](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/foggydude/32/636551_2.png) [@FoggyDude](https://forums.unrealengine.com/u/FoggyDude)\
**Post date:** [April 9, 2023, 12:35pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/2 "2023-04-09T12:35:53Z")

</div>

This is something I ran into myself, sadly don’t have a solution. Do you have any progress?

---

<div class="post-metadata">

**Author:** ![GraemeBB](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/graemebb/32/1106150_2.png) [@GraemeBB](https://forums.unrealengine.com/u/GraemeBB)\
**Post date:** [April 9, 2023, 3:30pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/3 "2023-04-09T15:30:29Z")

</div>

I want to know this too, I tried a pile of things as well but nothing worked. I think I saw on discord somewhere that it isn’t implemented yet? Not sure though.

---

<div class="post-metadata">

**Author:** ![FoggyDude](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/foggydude/32/636551_2.png) [@FoggyDude](https://forums.unrealengine.com/u/FoggyDude)\
**Post date:** [April 10, 2023, 10:16am UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/4 "2023-04-10T10:16:31Z")

</div>

Hey @DiG3! Help us out if you’ve got any insight in this topic, please 🙂

---

<div class="post-metadata">

**Author:** ![DiG3](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dig3/32/1225281_2.png) [@DiG3](https://forums.unrealengine.com/u/DiG3)\
**Post date:** [April 10, 2023, 11:40pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/5 "2023-04-10T23:40:02Z")

</div>

Hello,  
you can’t initialize a `listenable` interface inside a class.  
For now, I recommend exposing an event like the `CountdownEndedEvent` (for example `OnTimerIteration`/`OnTick`) that lets users of the class `Await` it. You’d then `Signal` the event when needed.

I haven’t played around with it much, but maybe something like this could also be helpful to you:

```auto
# In this case the functions we accept should take one string parameter and return void.
my_fun := type{_(:string):void}

my_subscribable := class:
    var Funs<private>:[]my_fun = array{}
    
    Subscribe<public>(Fun:my_fun):void =
        set Funs += array{Fun}
    
    Dispatch<private>():void =
        for (Fun:Funs):
            Fun("Hello")

```

---

<div class="post-metadata">

**Author:** ![UnrealVerseGuru](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@UnrealVerseGuru](https://forums.unrealengine.com/u/UnrealVerseGuru)\
**Post date:** [April 11, 2023, 5:29pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/6 "2023-04-11T17:29:15Z")

</div>

o/ Is there a way to implement custom `subcribable` events with generics?  
Ideally You’d want `my_subscribable` use `subscribable` and `signalable`, be parametric type passing t:type to `Funs` as you do.  
But seems we are hitting dead end of “sane” here with mutables not implemented in parametric types, so how would one go about using those interfaces in custom events?

By “sane” dead end I mean relatively not way-arounds approach, for example user Ep8Script#8819 posted this:

```auto
my_callback<internal>(t:type) := class:
    Callback<internal> : t -> void
    SpawnAwait<internal> : type{_(:t->void)<suspends>:void}

    OnSignal(Agent:?agent) : void =
        spawn {SpawnAwait(Callback)}

my_cancelable<internal> := class(cancelable):
    MaybeCancelable<internal> : ?cancelable = false

    Cancel<override>()<transacts> : void =
        if (Cancelable := MaybeCancelable?):
            Cancelable.Cancel()

my_subscribable<internal>(t:type) := class(listenable(t), signalable(t)):
    Event<private> : event(t) = event(t){}

    Await<override>()<suspends> : t =
        Event.Await()

    GetProxyTrigger<private>()<transacts> : ?trigger_device =
        var ProxyTrigger : ?trigger_device = false
        for (Actor : GetCreativeObjectsWithTag(subscribable_proxytrigger{})):
            if (Trigger := trigger_device[Actor]):
                set ProxyTrigger = option{Trigger}
        ProxyTrigger

    Signal<override>(Val:t) : void =
        if (Trigger := GetProxyTrigger()?):
            Trigger.Trigger()
        spawn {SleepSignal(Val)}

    SleepSignal<private>(Val:t)<suspends> : void =
        Sleep(0.0)
        Event.Signal(Val)

    SpawnAwait<private>(Callback:t -> void)<suspends> : void =
        Callback(Await())

    Subscribe<override>(Callback:t -> void)<transacts> : cancelable =
        var Cancelable : my_cancelable = my_cancelable{}
        if (Trigger := GetProxyTrigger()?):
            set Cancelable = my_cancelable{MaybeCancelable := option{Trigger.TriggeredEvent.Subscribe(my_callback(t){Callback := Callback, SpawnAwait := SpawnAwait}.OnSignal)}}
        Cancelable

subscribable_proxytrigger<public> := class(tag){}

my_class<public> := class:
    OnCustomEvent<public>() : listenable(int) = OnCustomEventSignaler
    OnCustomEventSignaler<private> : my_subscribable(int) = my_subscribable(int){}

    SomeInternalMethod<internal>(Number:int) : void =
        OnCustomEventSignaler.Signal(Number)

```

Havent tried it, but understandable question arises is there easier way 😃

---

<div class="post-metadata">

**Author:** ![spentak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spentak/32/642372_2.png) [@spentak](https://forums.unrealengine.com/u/spentak)\
**Post date:** [April 11, 2023, 6:06pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/7 "2023-04-11T18:06:10Z")

</div>

Ok this was my solution anyway haha. Thanks for letting me know

---

<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 6, 2023, 8:58pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/8 "2023-09-06T20:58:05Z")

</div>

I might have found a better way

```auto
custom_cancelable<public> := class:
    var Canceled : logic = false

    CancelEvent : event() = event(){}

    Cancel():void=
        set Canceled = true
        CancelEvent.Signal()

custom_subscribable<public>(t:type)<computes> := class<public>(awaitable(t)):

    InnerEvent : event(t) = event(t){}

    Subscribe(Callback:type {__(:t):void}):custom_cancelable=
        Cancelable := custom_cancelable{}
        spawn{_WaitForEvent(Callback, Cancelable)}

        Cancelable

    _WaitForEvent(Callback:type {__(:t):void}, Cancelable: custom_cancelable)<suspends>:void=
        race:
            # Wait for payload to be sent
            loop:
                Payload := InnerEvent.Await()

                # Just in case
                if(not Cancelable.Canceled?):
                    Callback(Payload)
                else:
                    break # Just in case

            # Cancelable got canceled
            Cancelable.CancelEvent.Await()

    
    Signal<public>(Payload:t):void =
        InnerEvent.Signal(Payload)

    Await<override>()<suspends>:t=
        InnerEvent.Await()

```

These might not be stored along in an array of `cancelable`, but it seem to work good (forgetting that it uses `spawns`)

EDIT: For anyone wanting to use this, just need to warn you, the garbage collector will not clean up the `suspending` calls  
So each `.Subscribe()` call will stay alive untill you manually call `.Cancel()` or `.CancelAll()`  
So to say, try to not dynamically generate `.Subscribe()` calls and you should be fine 👍

---

<div class="post-metadata">

**Author:** ![MarcosRocha](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/marcosrocha/32/741852_2.png) [@MarcosRocha](https://forums.unrealengine.com/u/MarcosRocha)\
**Post date:** [May 21, 2024, 3:27pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/9 "2024-05-21T15:27:16Z")

</div>

I’m getting “Can’t access a function from a preceding type” using this. Do that have any update?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/d/2/2d28560e4a3d0467670a2a4b78b9ec5254fea093.png)

---

<div class="post-metadata">

**Author:** ![YuyaShiotani](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/yuyashiotani/32/917612_2.png) [@YuyaShiotani](https://forums.unrealengine.com/u/YuyaShiotani)\
**Post date:** [June 2, 2024, 4:50am UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/10 "2024-06-02T04:50:22Z")

</div>

I’d like to try it, but like MarcosRocha, I see “Can’t access a function from a preceding type”. Do you have idea that avoid this error?

---

<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:** [June 2, 2024, 11:44am UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/11 "2024-06-02T11:44:15Z")

</div>

@YuyaShiotani @MarcosRocha

I’m not sure it works fine for me, are you trying to put this in a module or smth ?

---

<div class="post-metadata">

**Author:** ![TelesphorosGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/telesphorosgames/32/924355_2.png) [@TelesphorosGames](https://forums.unrealengine.com/u/TelesphorosGames)\
**Post date:** [June 3, 2024, 8:22am UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/12 "2024-06-03T08:22:25Z")

</div>

looks like the indenting might be a little off? oops, i may be seeing it wrong

---

<div class="post-metadata">

**Author:** ![MarcosRocha](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/marcosrocha/32/741852_2.png) [@MarcosRocha](https://forums.unrealengine.com/u/MarcosRocha)\
**Post date:** [July 1, 2024, 10:43pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/13 "2024-07-01T22:43:44Z")

</div>

Sorry for the delay. I copy pasted your code to a blank file (declaring needed using files) and got that.

---

<div class="post-metadata">

**Author:** ![CHENSHUO.L](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/chenshuo.l/32/978477_2.png) [@CHENSHUO.L](https://forums.unrealengine.com/u/CHENSHUO.L)\
**Post date:** [September 17, 2024, 10:09am UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/14 "2024-09-17T10:09:33Z")

</div>

Here I’ve writen a custom timer divice, which we can call any where in our code, with events call in every secound and on the end of the timer that we can subscribe.  
Check it here:

> **[GitHub - Chenshuo-Public-Code/UEFN-Custom-Timer: UEFN verse Custom Countdown Timer - with callback...](https://github.com/Chenshuo-Public-Code/UEFN-Custom-Timer)**
>
> UEFN verse Custom Countdown Timer - with callback functions

---

<div class="post-metadata">

**Author:** ![Jonny\_Gravity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jonny\_Gravity](https://forums.unrealengine.com/u/Jonny_Gravity)\
**Post date:** [February 13, 2025, 11:34am UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/15 "2025-02-13T11:34:50Z")

</div>

Sorry to resurrect an old thread, but for anyone coming here looking for this solution (which is awesome btw – thanks @im_a_lama!), the problem (“Can’t access a function from a preceding type”) is that parametric types can’t be referenced outside of the file that declared them (for now). The workaround for this is to place the file that’s using the custom listenable into it’s own submodule; this subverts the compiler error (and works!). So, you should have something like this:

```auto
MyProject/
-> Devices/
   -> your_listening_device.verse (instantiate the custom listenable here)
-> custom_listenable.verse

```

As opposed to:

```auto
MyProject/
-> your_listening_device.verse (instantiate the custom listenable here)
-> custom_listenable.verse

```

Just be careful if you decide to move your devices around… it’ll break any instances of the device in your editor. The (PITA) solution to this is to:

1. Create an intermediary device (copy/paste with a new name)
2. Copy/paste all of the config from the old device to the intermediary device
3. Move the old device, delete the original from the editor, and place the new one back into the editor
4. Copy/paste all of the config from the intermediary device to the new device
5. Delete the intermediary device

Don’t forge to copy over anything aside from configs as well (such as tags)

---

<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:** [February 13, 2025, 12:13pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/16 "2025-02-13T12:13:29Z")

</div>

I don’t recommend beginners to actually do so, creating folders will also create modules and it’s a hassle to work with, one can just rename `custom_subscribable.verse` to `_custom_subscribable.verse` forcing the parametric class to actually be compiled before any other code

---

<div class="post-metadata">

**Author:** ![Jonny\_Gravity](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jonny\_Gravity](https://forums.unrealengine.com/u/Jonny_Gravity)\
**Post date:** [February 15, 2025, 2:51pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/17 "2025-02-15T14:51:13Z")

</div>

😮 My solution above was recommended by an Epic dev in another thread elsewhere. It’s actually part of one of their tutorials.

I had no idea this would actually work. Does it really satisfy the linter? Cause it won’t let you compile otherwise. If so, I really wish I knew this before I migrated ALL of my devices to a submodule! That was a major PITA.

---

<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:** [February 18, 2025, 10:41am UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/18 "2025-02-18T10:41:24Z")

</div>

Like any other software developer, Epic members don’t always know how to use their tools, they’re making them, I know modules are recommended they’re just a hassle to use, especially with parametrics

Yes my solution works properly (as long as your file is at the root of your project ig?)

---

<div class="post-metadata">

**Author:** ![YvadKeebrev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@YvadKeebrev](https://forums.unrealengine.com/u/YvadKeebrev)\
**Post date:** [March 19, 2025, 11:25pm UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/19 "2025-03-19T23:25:56Z")

</div>

Hi, could maybe help me with how to Cancel the subscribe events? Can’t get it to work.

---

<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:** [March 20, 2025, 8:28am UTC](https://forums.unrealengine.com/t/how-do-you-implement-your-own-listenable-in-verse/832267/20 "2025-03-20T08:28:41Z")

</div>

Cancelable := SomeSubscribable.Subscribe()  
Cancelable.Cancel()
