Download

Async load next map in background

Hey guys,
Need some help to async a new map/level in the background and transition completely to it when it has finished loading.
I have a loading level, and a target level. The code nearly works, but it leaves behind the loading level.

I’m running the code from a game instance as you can see. Other than the loading level being left behind, it is otherwise working as expected.

Any help to get this functioning would be greatly appreciated!



void UTestGameInstance::RequestLoadMap(TArray<FName> RequestedTargetMap)
{
    if (RequestedTargetMap[0].IsValid())
    {
        UE_LOG(LogTemp, Warning, TEXT("RequestLoadMap: %s"), *RequestedTargetMap[0].ToString());

        GetWorld()->PrepareMapChange(RequestedTargetMap);
        IsMapRequested = true;
    }
}

void UTestGameInstance::RequestCheckMapReady()
{
    UE_LOG(LogTemp, Warning, TEXT("Checking map ready to load"));

    if (GetWorld()->IsMapChangeReady() && !IsAsyncLoading() && IsMapRequested)
    {
        GetWorld()->CommitMapChange();
        IsMapRequested = false;
    }
}


Or if anybody is able to suggest a completely alternate way to achieve this, that would be great!

Just for future reference:

  • Parent ghost level that will be the level
  • All game levels to be added as sub levels
  • Loading level to be added as sub level
  • Ghost level streams in loading level
  • Ghost level loads in target level, but doesnt make visible immedietly
  • On complettion of target level load and when player ready, unload loading level
  • Then make target level visible

Caveats

  • Ghost level now becomes a core part of game “engine”
  • Spawning of player needs to be done manually instead of using default in game mode. Otherwise the ghost map will spawn default pawn etc

Other considerations

  • BeginPlay on the sub levels, works as expected. It only triggers when you make the stream visible
  • BeginPlay on the ghost level still works as expected

This is exactly what Seamless Travel is for:
https://docs.unrealengine.com/en-us/…ing/Travelling

Edit: Looks like you want to load as a sub-level - in which case streaming levels should also be async…

Oh! Thanks, I’ll give that a read up!

I actually can’t get Seamless travel to work right for my use case - ghost level paradigm seems like it could work. For seamless travel, is it possible to reset the LoadingMap programmatically while the game is running?