Skip to content
Snippets Groups Projects
Commit 55cf2abb authored by Jonathan Ehret's avatar Jonathan Ehret
Browse files

fix to not being able to load a map and then switch back to the study setup map

parent d0144af0
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment