Improve the load of the sublevels

- We flush between sublevel load/unload calls to improve determinism
 - We have added a global uuid to allow the load/unload methods to be
called in the same tick
This commit is contained in:
Daniel Santos-Oliván 2021-06-21 11:50:28 +02:00 committed by DSantosO
parent b54d11d8f7
commit 96e9f35793
2 changed files with 13 additions and 5 deletions

View File

@ -441,6 +441,7 @@ void ACarlaGameModeBase::EnableEnvironmentObjects(
void ACarlaGameModeBase::LoadMapLayer(int32 MapLayers)
{
const UWorld* World = GetWorld();
UGameplayStatics::FlushLevelStreaming(World);
TArray<FName> LevelsToLoad;
ConvertMapLayerMaskToMapNames(MapLayers, LevelsToLoad);
@ -449,16 +450,17 @@ void ACarlaGameModeBase::LoadMapLayer(int32 MapLayers)
LatentInfo.CallbackTarget = this;
LatentInfo.ExecutionFunction = "OnLoadStreamLevel";
LatentInfo.Linkage = 0;
LatentInfo.UUID = 1;
LatentInfo.UUID = LatentInfoUUID;
PendingLevelsToLoad = LevelsToLoad.Num();
for(FName& LevelName : LevelsToLoad)
{
LatentInfoUUID++;
UGameplayStatics::LoadStreamLevel(World, LevelName, true, true, LatentInfo);
LatentInfo.UUID++;
LatentInfo.UUID = LatentInfoUUID;
UGameplayStatics::FlushLevelStreaming(World);
}
}
void ACarlaGameModeBase::UnLoadMapLayer(int32 MapLayers)
@ -471,15 +473,17 @@ void ACarlaGameModeBase::UnLoadMapLayer(int32 MapLayers)
FLatentActionInfo LatentInfo;
LatentInfo.CallbackTarget = this;
LatentInfo.ExecutionFunction = "OnUnloadStreamLevel";
LatentInfo.UUID = 1;
LatentInfo.UUID = LatentInfoUUID;
LatentInfo.Linkage = 0;
PendingLevelsToUnLoad = LevelsToUnLoad.Num();
for(FName& LevelName : LevelsToUnLoad)
{
LatentInfoUUID++;
UGameplayStatics::UnloadStreamLevel(World, LevelName, LatentInfo, false);
LatentInfo.UUID++;
LatentInfo.UUID = LatentInfoUUID;
UGameplayStatics::FlushLevelStreaming(World);
}
}

View File

@ -164,4 +164,8 @@ private:
bool ReadyToRegisterObjects = false;
// We keep a global uuid to allow the load/unload layer methods to be called
// in the same tick
int32 LatentInfoUUID = 0;
};