Hi everyone,
I’m facing a really strange problem,
I followed the tutorial in https://answers.unrealengine.com/questions/46503/how-to-use-preparemapchangecommitmapchange.html#answer-320371
Everything seems right but when I call GetWorld()->CommitMapChange() it’s not switching at all and it not even reload the first level even if my TArray of FName levels is correctly set.
And for proof the PreCommitChange is called with the rights PreviousMapName and NextMapName.
Did I missed something ?
UAsyncLoader::UAsyncLoader()
{
GetAllMapsDatas(Maps);
}
void UAsyncLoader::StartPreLoadingMap(uint8 Index)
{
TArray<FName> levelsToLoad;
levelsToLoad.Add(Maps[Index].PackageName);
UKismetSystemLibrary::PrintString(GetWorld(), *Maps[Index].PackageName.ToString(), true, true, FLinearColor::Yellow, 10.f);
GetWorld()->PrepareMapChange(levelsToLoad);
GetWorld()->GetTimerManager().SetTimer(TimerLoading, this, &UAsyncLoader::IsLoadingReady, 0.5f, true);
}
void UAsyncLoader::IsLoadingReady()
{
if (GetWorld()->IsMapChangeReady() && !IsAsyncLoading())
{
GetWorld()->GetTimerManager().ClearTimer(TimerLoading);
OnMapLoded.Broadcast();
}
}
void UAsyncLoader::LaunchMapTravel()
{
GetWorld()->CommitMapChange();
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("Commit Map"), true, true, FLinearColor::Yellow, 10.f);
}
bool UAsyncLoader::GetAllMapsDatas(TArray<FAssetData>& mapsArray)
{
// Create a library of UWorlds
UObjectLibrary* objectLibrary = UObjectLibrary::CreateLibrary(UWorld::StaticClass(), false, true);
// Loads all the maps from the given path inside the library
objectLibrary->LoadAssetDataFromPath(TEXT("/Game/Maps"));
// Get all the metadatas from the library
objectLibrary->GetAssetDataList(mapsArray);
//FString debug = "Found Maps = " + FString::FromInt(mapDatas.Num());
//UKismetSystemLibrary::PrintString(GetWorld(), *debug, true, true, FLinearColor::Yellow, 10.f);
if (mapsArray.Num() > 0)
{
return true;
}
return false;
}
And when the OnMapLoaded is triggered it enables a button to actually launch the commit. When I click it the PreCommitMapCHange is called with the right arguments and PostCommitChange is fired then but when I do GetWorld()->GetFullName() I’m still on the same level.
Best regards,
Alexandre