# Asynchronous Level Travel

**URL:** <https://forums.unrealengine.com/t/asynchronous-level-travel/2013771>\
**Category:** Programming & Scripting\
**Tags:** async, unreal-engine, CPP, question\
**Created:** [September 9, 2024, 9:09pm UTC](https://forums.unrealengine.com/t/asynchronous-level-travel/2013771 "2024-09-09T21:09:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suspensium](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Suspensium](https://forums.unrealengine.com/u/Suspensium)\
**Post date:** [September 9, 2024, 9:09pm UTC](https://forums.unrealengine.com/t/asynchronous-level-travel/2013771/1 "2024-09-09T21:09:20Z")

</div>

My setup is as follows:  
I press a button on my widget to try a hero:

```auto
void UHeroInfoWidget::OnTryHeroButtonPressed()
{
	UTBCGameInstance* GameInstance{GetGameInstance<UTBCGameInstance>()};
	_LIKELY if (GameInstance)
	{
		GameInstance->SetPlayerCharacterClass(HeroInfo.CharacterClass.Get());

		GameInstance->AsyncLoadMap(TryHeroLevel);
	}
}

```

It asynchronously loads TSoftObjectPtr TryHeroLevel map:

```auto
void UTBCGameInstance::AsyncLoadMap(const TSoftObjectPtr<UWorld>& Map, const bool bShowMapAfterLoad)
{
	const FLoadPackageAsyncDelegate LoadDelegate{
		FLoadPackageAsyncDelegate::CreateUObject(
			this, &UTBCGameInstance::OnAsyncLoadMapCompleted, bShowMapAfterLoad)
	};

	LoadPackageAsync(Map.GetLongPackageName(), LoadDelegate, PKG_ContainsMap);
}

void UTBCGameInstance::OnAsyncLoadMapCompleted(const FName& PackageName, UPackage* LoadedPackage,
                                               const EAsyncLoadingResult::Type Result,
                                               const bool bShowMapAfterLoad) const
{
	if (Result == EAsyncLoadingResult::Succeeded && bShowMapAfterLoad)
	{
		UGameplayStatics::OpenLevel(this, PackageName);
	}
}

```

It works as intended, main game thread doesn’t lock, nothing freezes.  
However, I face a problem when trying to enter a TransitionLevel while TryHeroLevel is loading.  
If I add a OpenLevel synchronous function in widget like so:

```auto
void UHeroInfoWidget::OnTryHeroButtonPressed()
{
	UTBCGameInstance* GameInstance{GetGameInstance<UTBCGameInstance>()};
	_LIKELY if (GameInstance)
	{
		GameInstance->SetPlayerCharacterClass(HeroInfo.CharacterClass.Get());

		UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), GameInstance->GetTransitionMap());

		GameInstance->AsyncLoadMap(TryHeroLevel);
	}
}

```

my main thread freezes, I see transition map for a slight moment before being moved to TryHero level. I’m not sure how to handle this correctly besides just adding TransitionWidget on screen and not moving to TransitionLevel. Any insights?
