# want to cancel a listenable await

**URL:** <https://forums.unrealengine.com/t/want-to-cancel-a-listenable-await/1449168>\
**Category:** Verse\
**Tags:** unreal-engine, unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [December 2, 2023, 6:09am UTC](https://forums.unrealengine.com/t/want-to-cancel-a-listenable-await/1449168 "2023-12-02T06:09:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eisuke114](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/eisuke114/32/758029_2.png) [@Eisuke114](https://forums.unrealengine.com/u/Eisuke114)\
**Post date:** [December 2, 2023, 6:09am UTC](https://forums.unrealengine.com/t/want-to-cancel-a-listenable-await/1449168/1 "2023-12-02T06:09:50Z")

</div>

I want to cancel a listenable await. In the following code, the `MutetDisable` method is used to disable it, but the await remains. What should I do?

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

TaxiJob_device := class(creative_device):

    @editable
    TaxiSalary:int = 100

    @editable
    JobZone:[]mutator_zone_device = array{}

    @editable
    taxi:vehicle_spawner_taxi_device = vehicle_spawner_taxi_device{}

    SuccessEvent<public>:event(int) = event(int){}

    var count : int = 0
    var isEnd : logic = false

    OnBegin<override>()<suspends>:void=
        MutetDisable()
        taxi.AgentEntersVehicleEvent.Subscribe(OnStartJob)
        taxi.AgentExitsVehicleEvent.Subscribe(OnEndJob)

    OnStartJob(Agent : agent):void=
        Print("TaxiJob started")
        set isEnd = false
        spawn { OnJobbing() }

    OnEndJob(Agent : agent):void=
        Print("TaxiJob ended")
        set isEnd = true
        MutetDisable

    OnJobbing()<suspends>:void=
        Print("TaxiJob jobbing")
        rand := GetRandomInt(0, JobZone.Length-1)
        NextActiveZone(rand)

    NextActiveZone(nowRand : int)<suspends>:void=
        nextRand := GetDiffrentRandomValue(nowRand)
        if (nowZone := JobZone[nowRand]):
            nowZone.Enable()
            nowZone.AgentEntersEvent.Await()
            nowZone.Disable()
            Print("TaxiJob Success!!")
            if (isEnd = false):
                Salary := TaxiSalary + count
                SuccessEvent.Signal(Salary)
                set count += 1
                NextActiveZone(nextRand)
            else:
                Print("TaxiJob End")
                return

    GetDiffrentRandomValue(value : int):int=
        rand := GetRandomInt(0, JobZone.Length-1)
        if (rand = value):
            return GetDiffrentRandomValue(value)
        return rand

    MutetDisable()<suspends>:void=
        for (zone : JobZone):
            zone.Disable()

```

---

<div class="post-metadata">

**Author:** ![bananna\_manuk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bananna\_manuk](https://forums.unrealengine.com/u/bananna_manuk)\
**Post date:** [December 2, 2023, 10:03pm UTC](https://forums.unrealengine.com/t/want-to-cancel-a-listenable-await/1449168/2 "2023-12-02T22:03:29Z")

</div>

you need to unsubscribe

> [@How do I unsubscribe from a player event?](https://forums.unrealengine.com/t/how-do-i-unsubscribe-from-a-player-event/835731):
>
> How do I unsubscribe from an event on a specific element? Right now I have subscribed to the control change event of a capture area. Later I want to reset that capture area so it can be captured by the same team again, but when I reset the capture area it calls the subscribed event, which throughs everything into disarray. If I can just cancel the subscription between capturing and resetting the capture area everything should work.

---

<div class="post-metadata">

**Author:** ![LionUnchained](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lionunchained/32/1039015_2.png) [@LionUnchained](https://forums.unrealengine.com/u/LionUnchained)\
**Post date:** [December 3, 2023, 12:41pm UTC](https://forums.unrealengine.com/t/want-to-cancel-a-listenable-await/1449168/3 "2023-12-03T12:41:33Z")

</div>

If you assign the subscription to a variable you can call cancel using that variable.

```auto
DamageSubscribe := Fort.DamagedEvent().Subscribe(OnPlayerDamaged)

DamageSubscribe.Cancel()

```

---

<div class="post-metadata">

**Author:** ![Eisuke114](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/eisuke114/32/758029_2.png) [@Eisuke114](https://forums.unrealengine.com/u/Eisuke114)\
**Post date:** [December 3, 2023, 3:38pm UTC](https://forums.unrealengine.com/t/want-to-cancel-a-listenable-await/1449168/4 "2023-12-03T15:38:02Z")

</div>

Sorry, my information was insufficient.  
I am trying to cancel `Await` in the following part.

```auto
            nowZone.Enable()
            AgentEntersEvent.Await()
            Disable()

```

---

<div class="post-metadata">

**Author:** ![Eisuke114](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/eisuke114/32/758029_2.png) [@Eisuke114](https://forums.unrealengine.com/u/Eisuke114)\
**Post date:** [December 4, 2023, 5:43am UTC](https://forums.unrealengine.com/t/want-to-cancel-a-listenable-await/1449168/5 "2023-12-04T05:43:42Z")

</div>

By the way, I tried changing from Await to using Subscribe but it did not work properly.

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

TaxiJob_device := class(creative_device):

    @editable
    TaxiSalary:int = 10000

    @editable
    EnableOrder:int = 0

    @editable
    JobZone:[]mutator_zone_device = array{}

    @editable
    taxi:vehicle_spawner_taxi_device = vehicle_spawner_taxi_device{}

    SuccessEvent<public>:event(int) = event(int){}

    var count : int = 0
    var isEnd : logic = false
    var defaultTransform : transform = transform{}
    var ControlChangeSubscription:?cancelable = false
    var Zone : mutator_zone_device = mutator_zone_device{}
    var NextRand : int = 0

    OnBegin<override>()<suspends>:void=
        GetTaxiTransform()
        MoveTaxi()
        MutetDisable()
        for (zone : JobZone):
            zone.Disable()
        taxi.AgentEntersVehicleEvent.Subscribe(OnStartJob)
        taxi.AgentExitsVehicleEvent.Subscribe(OnEndJob)

    GetTaxiTransform()<suspends>:void=
        set defaultTransform = taxi.GetTransform()

    MoveTaxi()<suspends>:void=
        NewRotation := rotation{}
        vec := vector3{X:=1000.0, Y:=1000.0, Z:=0.0}
        if(taxi.TeleportTo[vec, NewRotation]):
            Print("MoveTrigger")

    ReturnTaxi()<suspends>:void=
        if(taxi.TeleportTo[defaultTransform]):
            taxi.RespawnVehicle()
            Print("ReturnTrigger")

    OnStartJob(Agent : agent):void=
        Print("TaxiJob started")
        set isEnd = false
        spawn { OnJobbing() }

    OnEndJob(Agent : agent):void=
        Print("TaxiJob ended")
        set isEnd = true
        MutetDisable

    OnJobbing()<suspends>:void=
        Print("TaxiJob jobbing")
        rand := GetRandomInt(0, JobZone.Length-1)
        NextActiveZone(rand)

    NextActiveZone(nowRand : int)<suspends>:void=
        nextRand := GetDiffrentRandomValue(nowRand)
        set NextRand = nextRand
        if (nowZone := JobZone[nowRand]):
            nowZone.Enable()
            set Zone = nowZone
            Temp:cancelable = Zone.AgentEntersEvent.Subscribe(ZoneSubscribe)
            set ControlChangeSubscription = option { Temp } 

    ZoneSubscribe(Agent : agent):void=
        Zone.Disable()
        Print("TaxiJob Success!!")
        if (isEnd = false):
            Salary := TaxiSalary + count
            SuccessEvent.Signal(Salary)
            set count += 1000
            spawn {NextActiveZone(NextRand)}
        else:
            Print("TaxiJob End")
            return
            

    GetDiffrentRandomValue(value : int):int=
        rand := GetRandomInt(0, JobZone.Length-1)
        if (rand = value):
            return GetDiffrentRandomValue(value)
        return rand

    MutetDisable()<suspends>:void=
        if (Subscription := ControlChangeSubscription?):
            Print("TaxiJob Disable")
            Subscription.Cancel()
            Zone.Disable()
    

    GetOrder<public>():int=
        return EnableOrder

    Enable<public>():void=
        spawn { ReturnTaxi() }

```

Print(“TaxiJob Disable”)` is no longer called in the following code section.

```auto
    MutetDisable()<suspends>:void=
        if (Subscription := ControlChangeSubscription?):
            Print("TaxiJob Disable")
            Subscription.Cancel()
            Zone.Disable()

```
