# Race is finished but one can still trigger event inside of it

**URL:** <https://forums.unrealengine.com/t/race-is-finished-but-one-can-still-trigger-event-inside-of-it/2089238>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [October 26, 2024, 2:24pm UTC](https://forums.unrealengine.com/t/race-is-finished-but-one-can-still-trigger-event-inside-of-it/2089238 "2024-10-26T14:24:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dr.Joske](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dr.joske/32/1014311_2.png) [@Dr.Joske](https://forums.unrealengine.com/u/Dr.Joske)\
**Post date:** [October 26, 2024, 2:24pm UTC](https://forums.unrealengine.com/t/race-is-finished-but-one-can-still-trigger-event-inside-of-it/2089238/1 "2024-10-26T14:24:05Z")

</div>

Hi, I typed this simple code to try to figure out where was the problem,  
in short race is finished but one can still trigger event inside of it, I wonder why?

```auto
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }

problem<public> := class<concrete>(creative_device):

    Break1 : event() = event(){}
    Break2 : event() = event(){}
    Wait1 : event() = event(){}
    Wait2 : event() = event(){}

    OnBegin<override>()<suspends> : void =
        
        #if you follow TestRun and AllInOneFunction, you will expect output to be 0,1 

        #but thats not the case for some reason, here are 2 different ways to write the same thing

        #1 style

        Print("unreliable")

        race:
            TestRun()
            AllInOneFunction()
        
        #result is wrong 0,1,0,0

        #2 style

        Print("good")
        
        race:
            TestRun()
            Part1()

        #result is correct 0,1

    TestRun()<suspends>:void=
        Sleep(0.1)
        Wait1.Signal()
        Sleep(0.1)
        Wait2.Signal()
        Sleep(0.1)
        Break1.Signal()
        Sleep(0.1)
        Wait2.Signal()
        Sleep(0.1)
        Wait2.Signal()
        Sleep(0.1)

    #1 style

    AllInOneFunction()<suspends>:void=
        loop:
            Wait1.Await()
            race:
                Break1.Await()
                loop:
                    race:
                        Break2.Await()
                        loop:
                            Wait2.Await()
                            Print("0")
            Print("1")

    #2 style

    Part1()<suspends>:void=
        loop:
            Wait1.Await()
            race:
                Break1.Await()
                Part2()
            Print("1")

    Part2()<suspends>:void=
        loop:
            race:
                Break2.Await()
                Part3()

    Part3()<suspends>:void=
        loop:
            Wait2.Await()
            Print("0")

 

    #SIMPLE VERSION
    
    Something : event() = event(){}
    
    Smth()<suspends>:void=

    #1 style When used within multiple loops/races gives unexpected result

        race:
            Something.Await()
            loop:
                Sleep(1.0)
                numb := 2+2
            block:
                Print("ABC")
                Sleep(2.0)
            
                
    #2 style When used within multiple loops/races gives expected result

        race:
            Something.Await()
            Function1()
            Function2()

    Function1()<suspends>:void=
        loop:
            Sleep(1.0)
            numb := 2+2

    Function2()<suspends>:void=
        Print("ABC")
        Sleep(2.0)

```

---

<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:** [October 28, 2024, 2:38am UTC](https://forums.unrealengine.com/t/race-is-finished-but-one-can-still-trigger-event-inside-of-it/2089238/3 "2024-10-28T02:38:33Z")

</div>

Could be related

> [@\[CRITICAL\] Defer does not execute after cancellation through race](https://forums.unrealengine.com/t/critical-defer-does-not-execute-after-cancellation-through-race/2077174):
>
> Summary Here’s the repro using { /Fortnite.com/Devices } using { /Verse.org/Simulation } test\_device := class(creative\_device): StartFail()\<suspends\>:void= Print("StartFail") defer: Print("StartFail Ended (from suspending scope)") # Never prints race: Sleep(Inf) Sleep(Inf) Sleep(Inf) StartSucceed()\<suspends\>:void= Print("StartSucceed") defer: Print("StartSucceed Ended (from suspe…

---

<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:** [October 28, 2024, 12:20pm UTC](https://forums.unrealengine.com/t/race-is-finished-but-one-can-still-trigger-event-inside-of-it/2089238/4 "2024-10-28T12:20:02Z")

</div>

Hey again, I went ahead and reported your issue, I tried to make it a bit simpler though

> [@Loop inside embed loop+race structure never gets cancelled](https://forums.unrealengine.com/t/critical-loop-inside-embed-loop-race-structure-never-gets-cancelled/2092296):
>
> Summary Here’s the repro using { /Fortnite.com/Devices } using { /Verse.org/Simulation } test\_device := class(creative\_device): OnBegin\<override\>()\<suspends\> : void = loop: # Fake loop, will only iterate once Print("START RACE") race: Sleep(1.0) loop: race: Sleep(Inf) loop: Sleep(0.4) Print("LOOPING") #…

> [@Dr.Joske](#):
>
> ```auto
> race:
> Break2.Await()
> loop:
> Wait2.Await()
> Print("0")
> 
> ```

Apparently, if you put this whole part inside a method, it will fix your issue

---

<div class="post-metadata">

**Author:** ![Dr.Joske](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dr.joske/32/1014311_2.png) [@Dr.Joske](https://forums.unrealengine.com/u/Dr.Joske)\
**Post date:** [October 28, 2024, 6:51pm UTC](https://forums.unrealengine.com/t/race-is-finished-but-one-can-still-trigger-event-inside-of-it/2089238/5 "2024-10-28T18:51:12Z")

</div>

Thanks for reporting it as a bug and making simpler version.  
I also liked Sleep(Inf), never seen that one before 🙂
