# Async Task Crash

**URL:** <https://forums.unrealengine.com/t/async-task-crash/1917305>\
**Category:** Programming & Scripting\
**Tags:** async, unreal-engine, CPP\
**Created:** [June 26, 2024, 1:34pm UTC](https://forums.unrealengine.com/t/async-task-crash/1917305 "2024-06-26T13:34:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Feanor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Feanor](https://forums.unrealengine.com/u/Feanor)\
**Post date:** [June 26, 2024, 1:34pm UTC](https://forums.unrealengine.com/t/async-task-crash/1917305/1 "2024-06-26T13:34:46Z")

</div>

I would like to run a process asynchronously and execute a delegate when it is completed, when this happens between operations an audio is played.  
Code is like:

```auto
AsyncTask(ENamedThreads::AnyThread, [this]()
{
    ...
   AsyncTask(ENamedThreads::GameThread, [this]()
	{
		ChunkState = EChunkState::Recognized;
		OnChunkComplete.ExecuteIfBound(this);
	});
})

```

I also tried adding a nexttick on the bounded function.

```auto
GetWorld()->GetTimerManager().SetTimerForNextTick([this]{
    ....
    AudioComponent->Play();
});

```

but crashes occur on the function:  
IsInGameThread()  
FTimerHandle FTimerManager::InternalSetTimerForNextTick(FTimerUnifiedDelegate&& InDelegate): 533

or  
IsInGameThread() [File:D:\build++UE5\Sync\Engine\Source\Runtime\Engine\Private\AudioDevice.cpp] [Line: 5925]

How I can solve this crashes?

Thanks

---

<div class="post-metadata">

**Author:** ![6r0m](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/6r0m/32/1194563_2.png) [@6r0m](https://forums.unrealengine.com/u/6r0m)\
**Post date:** [July 5, 2024, 12:58pm UTC](https://forums.unrealengine.com/t/async-task-crash/1917305/2 "2024-07-05T12:58:03Z")

</div>

in both cases as in the info from the functions - check Game Thread failed.

and as a result, I would suggest that you can’t play Audio in not in the Game Thread.  
Audio will be played in the separated thread anyway, but before this it wants some Game Thread preparation - I guess to synchronize relevant data.

and not only in your callback and all Game Thread relative function calls, you need to make sure that they will be on Game Thread.

---

<div class="post-metadata">

**Author:** ![Neelerak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/neelerak/32/955144_2.png) [@Neelerak](https://forums.unrealengine.com/u/Neelerak)\
**Post date:** [July 6, 2024, 2:09am UTC](https://forums.unrealengine.com/t/async-task-crash/1917305/3 "2024-07-06T02:09:29Z")

</div>

Audio must be played in a GameThread, that is obvious, cause that is the error. The question seems to be as to how, rather than if. Here is how you would make sure this task is in a game thread. You can put this AsyncTask in any code block.

```auto
AsyncTask(ENamedThreads::GameThread, [AudioComponent, this]()
{
AudioComponent->Play();
});

```

Hope that helps, 😉
