Using the “Open Level by Reference” Blueprint Node (or calling the equivalent function, UGameplayStatics::OpenLevelBySoftObjectPtr) results in a failure to load package if it’s attempted from a map opened during the PIE session (e.g. running an “open level” node during a play session and then attempting to run “open level by reference” from the newly loaded level).
This only happens in PIE and is not present in Standalone or Packaged.
The error itself is printed on line 12873 of UnrealEngine.cpp, found in this section of code:
// See if the level is already in memory
WorldPackage = FindPackage(nullptr, *URL.Map);
bool bPackageAlreadyLoaded = (WorldPackage != nullptr);
// If the level isn't already in memory, load level from disk
if (WorldPackage == nullptr)
{
WorldPackage = LoadPackage(nullptr, *URL.Map, (WorldContext.WorldType == EWorldType::PIE ? LOAD_PackageForPIE : LOAD_None));
}
// Clean up the world type list now that PostLoad has occurred
UWorld::WorldTypePreLoadMap.Remove( URLMapFName );
if (WorldPackage == nullptr)
{
// it is now the responsibility of the caller to deal with a NULL return value and alert the user if necessary
Error = FString::Printf(TEXT("Failed to load package '%s'"), *URL.Map);
return false;
}
This might be related to how levels are cloned during PIE sessions.
Repro Steps:
- Create a new project (in my case, I used the third person template)
- Add some method to travel back and forth between two levels using both nodes: “Open Level by Reference” and “Open Level by Name” (I created two actors with a collider. When touched, they run the appropriate node).
- Play in PIE and try moving back and forth between the levels using the “Open Level by Name” node. It should work as intended.
- Play in PIE and try moving back and forth between the levels using the “Open Level by Reference” node. It will fail from the 2nd attempt onwards.