diff --git a/Source/StudyFrameworkPlugin/Private/SFMapFactor.cpp b/Source/StudyFrameworkPlugin/Private/SFMapFactor.cpp index 31c5aa5292ba17e43c84bd89ca833ce04dbd5c9f..cc2d3c986dcfafe684506898da428dbad15de6f9 100644 --- a/Source/StudyFrameworkPlugin/Private/SFMapFactor.cpp +++ b/Source/StudyFrameworkPlugin/Private/SFMapFactor.cpp @@ -19,24 +19,22 @@ void USFMapFactor::FromJson(TSharedPtr<FJsonObject> Json) for(FString LevelName : Levels) { - //we had issues with maps being loaded once in the editor and then on starting the study this method - //was called again in PostLoad() and tried to reload an already loaded map which caused crashes - //with the if-clause below we do not load the maps when starting the study, where we don't need the - //asset pointer anyways since the study itself only uses the Levels strings directly - UWorld* World = GetWorld(); - if(World && World->WorldType != EWorldType::PIE && World->WorldType != EWorldType::Game) - { - TSoftObjectPtr<UWorld> LevelObj = StaticLoadObject(UWorld::StaticClass(), nullptr, *LevelName, nullptr, LOAD_Verify | LOAD_Quiet); - Maps.Add(LevelObj.Get()); - - } + // we need to transform /Path/To/Asset into /Path/To/Asset.Asset; + TArray<FString> Parts; + LevelName.ParseIntoArray(Parts,TEXT("/"),true); + FString LevelNameFull = LevelName + "." + Parts[Parts.Num()-1]; + + FSoftObjectPath LevelPath(LevelNameFull); + TSoftObjectPtr<UWorld> LevelObj(LevelPath); + LevelObj.ToSoftObjectPath().PostLoadPath(nullptr); + Maps.Add(LevelObj); } } #if WITH_EDITOR bool USFMapFactor::CanEditChange(const FProperty* InProperty) const { - //just use this to not allow editing "Levels" directly at all + // just use this to not allow editing "Levels" directly at all if (InProperty->GetFName() == "Levels") { return false; @@ -54,6 +52,8 @@ void USFMapFactor::PostEditChangeProperty(FPropertyChangedEvent& PropertyChanged Levels.Empty(); for(TSoftObjectPtr<UWorld> Map : Maps) { + // we want to store the name as /Path/To/Asset not as /Path/To/Asset.Asset + // this is beneficial for readability and also needed for loading the levels as is now FSoftObjectPath Path = Map.ToSoftObjectPath(); FString PathString = Path.GetAssetPathString(); int32 DotIndex;