# Help with how to use Race and concurrency

**URL:** <https://forums.unrealengine.com/t/help-with-how-to-use-race-and-concurrency/2536126>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [June 1, 2025, 6:07am UTC](https://forums.unrealengine.com/t/help-with-how-to-use-race-and-concurrency/2536126 "2025-06-01T06:07:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DogOnAKeyboard13](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DogOnAKeyboard13](https://forums.unrealengine.com/u/DogOnAKeyboard13)\
**Post date:** [June 1, 2025, 6:07am UTC](https://forums.unrealengine.com/t/help-with-how-to-use-race-and-concurrency/2536126/1 "2025-06-01T06:07:42Z")

</div>

Hi there,

I have a class object that runs a “run\_lifetime” function that sleeps for X seconds and then sets a flag variable “isActive” to false.

I also have a collectible object device that has a subscribed function for the OnCollected event. When a player collects the object, then the same isActive variable will get set to false.

I set up the object and collectible so they go back into an “unused” stack (isActive should be false for those objects there). The issue is when a player will collect an active collectible object, the object goes to this inactive stack and when the object then becomes active shortly again, I think its lifetime timer is still running and going to set the flag isActive to false when it’s actually still in use.

Basically I want to know how to cancel the run\_lifetime async function or use a race setup to make it so that when a player collects the object and the OnCollected function happens, the run\_lifetime function does not continue. Does anyone know how to set this up in this scenario?

---

<div class="post-metadata">

**Author:** ![Starkiller9229](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Starkiller9229](https://forums.unrealengine.com/u/Starkiller9229)\
**Post date:** [June 3, 2025, 12:25pm UTC](https://forums.unrealengine.com/t/help-with-how-to-use-race-and-concurrency/2536126/2 "2025-06-03T12:25:26Z")

</div>

To set up a race for the two you can try the following

```auto
race:
    run_lifetime()
    block:
        collectible.OnColleted.Await()
        # Deactivate the collectible
        # Add it to the stack

```

This way, the run\_lifetime will be cancelled if the collectible is collected before it completes.

---

<div class="post-metadata">

**Author:** ![DogOnAKeyboard13](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DogOnAKeyboard13](https://forums.unrealengine.com/u/DogOnAKeyboard13)\
**Post date:** [June 3, 2025, 9:46pm UTC](https://forums.unrealengine.com/t/help-with-how-to-use-race-and-concurrency/2536126/3 "2025-06-03T21:46:19Z")

</div>

Thank you so much! I actually was coming back to say I also had figured it out, which is the way you pretty much wrote it too! 😊 I am new to using Race and didn’t know how it worked with the events (haven’t used Await before), thanks I appreciate the reply

Yeah I wrote a singular function to do that race block

```auto
    doRaceItemBoxEvent(itemManager_counter : itemManagerStats)<suspends>:void =
        # race function for handling which event happens first - collecting item box by player or lifetime timer running out
        # should cancel the other event when one has occurred
        # this avoids issues with setting flags if a player collects it and the lifetime timer were to continue

        maybeCollectible := Get_itemBoxCollectible() # returns an option var of collectible_object_device

        if (currCollectible := maybeCollectible?):
            race:
                block:
                    Run_lifetimeTimer(itemManager_counter)
                block:
                    currCollectible.CollectedEvent.Await()

```

(there’s other code that handles all the other details of “creating” / “destroying” the collectible item box objects but those are tested and work separately from this).

I tested it in the game and my item box collectible objects no longer have the issue of their lifetime being cut short anymore 😁 thanks again~

---

<div class="post-metadata">

**Author:** ![Starkiller9229](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Starkiller9229](https://forums.unrealengine.com/u/Starkiller9229)\
**Post date:** [June 4, 2025, 1:35pm UTC](https://forums.unrealengine.com/t/help-with-how-to-use-race-and-concurrency/2536126/4 "2025-06-04T13:35:42Z")

</div>

Nice one for figuring it out. Glad you got it working 🙂
