# AsyncTask to load meshes crashing game

**URL:** <https://forums.unrealengine.com/t/asynctask-to-load-meshes-crashing-game/1268789>\
**Category:** C++\
**Tags:** async, unreal-engine\
**Created:** [August 22, 2023, 1:02pm UTC](https://forums.unrealengine.com/t/asynctask-to-load-meshes-crashing-game/1268789 "2023-08-22T13:02:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cafragachan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cafragachan](https://forums.unrealengine.com/u/cafragachan)\
**Post date:** [August 22, 2023, 1:02pm UTC](https://forums.unrealengine.com/t/asynctask-to-load-meshes-crashing-game/1268789/1 "2023-08-22T13:02:09Z")

</div>

I am trying to spawn multiple actors at runtime and load meshes (uassets) from the content folder. I started to look at AsyncTask to do the job but I am struggling to get it to work. Any help would be greatly appreciated. This is the object class:

```auto
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnStaticMeshLoaded, UStaticMesh*, mesh);

UCLASS()
class AALTERMODULAR_API AOSMAsyncMeshObj : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AOSMAsyncMeshObj();

public:	

	UPROPERTY(EditAnywhere)
		USceneComponent* Root;

	UPROPERTY(EditAnywhere)
		UStaticMeshComponent* Mesh;

	UFUNCTION()
		void Initialise(FString MeshPath);

	UFUNCTION()
		void SetObjMesh(UStaticMesh* mesh_);

```

And .cpp:

```auto
void AOSMAsyncMeshObj::Initialise(FString MeshPath)
{
	FOnStaticMeshLoaded OnMeshLoaded;
	OnMeshLoaded.AddDynamic(this, &AOSMAsyncMeshObj::SetObjMesh);

	AsyncTask(ENamedThreads::AnyHiPriThreadHiPriTask, [OnMeshLoaded]()
		{
			TArray<UStaticMesh*> directoryMeshes = UaUtilities::GetMeshesFromDirectory("Assets/TwinmotionReadyposed/PosedHumans/meshes");
			int32 index = FMath::RandRange((int32)0, (int32)directoryMeshes.Num() - 1);
			OnMeshLoaded.Broadcast(directoryMeshes[index]);
		});
}

void AOSMAsyncMeshObj::SetObjMesh(UStaticMesh* mesh_)
{
	Mesh->SetStaticMesh(mesh_);
}

```

Currently the game is crashing with the following error:

Assertion failed: IsInGameThread() [File:D:\build++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 1549] Unable to load /Game/Assets/TwinmotionReadyposed/PosedHumans/meshes/SM\_Child01. Objects and Packages can only be loaded from the game thread.

How to get asynchronous logic out of the GameThread then?

---

<div class="post-metadata">

**Author:** ![DeathRaceReal](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DeathRaceReal](https://forums.unrealengine.com/u/DeathRaceReal)\
**Post date:** [February 10, 2024, 6:01pm UTC](https://forums.unrealengine.com/t/asynctask-to-load-meshes-crashing-game/1268789/2 "2024-02-10T18:01:11Z")

</div>

TLDR: you can’t. UObjects don’t allow this. You will have to do this on the game thread instead / hack it somehow
