# Loop inside embed loop+race structure never gets cancelled

**URL:** <https://forums.unrealengine.com/t/loop-inside-embed-loop-race-structure-never-gets-cancelled/2092296>\
**Category:** Issues and Bug Reporting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [October 28, 2024, 12:18pm UTC](https://forums.unrealengine.com/t/loop-inside-embed-loop-race-structure-never-gets-cancelled/2092296 "2024-10-28T12:18:40Z")\
**Posts on this page:** 3\
**Page:** 1

<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:18pm UTC](https://forums.unrealengine.com/t/loop-inside-embed-loop-race-structure-never-gets-cancelled/2092296/1 "2024-10-28T12:18:40Z")

</div>

### Summary

Here’s the repro

```auto
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") # Never stops printing

            Print("END RACE") # Prints after 1s
            Sleep(Inf)

```

Will print

```auto
[2024.10.28-12.16.18:084][709]LogVerse: : START RACE
[2024.10.28-12.16.18:485][756]LogVerse: : LOOPING
[2024.10.28-12.16.18:885][804]LogVerse: : LOOPING
[2024.10.28-12.16.19:085][828]LogVerse: : END RACE
[2024.10.28-12.16.19:285][852]LogVerse: : LOOPING
[2024.10.28-12.16.19:695][901]LogVerse: : LOOPING
[2024.10.28-12.16.20:097][949]LogVerse: : LOOPING
[2024.10.28-12.16.20:498][997]LogVerse: : LOOPING
[2024.10.28-12.16.20:898][45]LogVerse: : LOOPING
[2024.10.28-12.16.21:298][93]LogVerse: : LOOPING
... # Infinite looping

```

### Please select what you are reporting on:

Verse

### What Type of Bug are you experiencing?

Verse

### Steps to Reproduce

See repro

### Expected Result

See repro

### Observed Result

See repro

### Platform(s)

PC

---

<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/loop-inside-embed-loop-race-structure-never-gets-cancelled/2092296/2 "2024-10-28T12:20:47Z")

</div>

Found by @Dr.Joske ([Race is finished but one can still trigger event inside of it](https://forums.unrealengine.com/t/race-is-finished-but-one-can-still-trigger-event-inside-of-it/2089238))

---

<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:53pm UTC](https://forums.unrealengine.com/t/loop-inside-embed-loop-race-structure-never-gets-cancelled/2092296/3 "2024-10-28T12:53:55Z")

</div>

Apparently, this is the fix (move the whole race inside a method, I didn’t know races where aware of their suspending method, I thought they would be aware of their suspending scope only)

```auto
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:
                    LoopPrint()

            Print("END RACE") # Prints after 1s
            Sleep(Inf)
        
    LoopPrint()<suspends>:void=
        race:
            Sleep(Inf)
            loop:
                Sleep(0.4)
                Print("LOOPING")

```
