(39) 's Extra Blueprint Nodes for You as a Plugin, No C++ Required!

Load Level Instance, Load Multiple Transformed Instances of Same Level, not in Levels List! :heart:

Dear Community,

New: Please note I’ve now made a pull request for Node to the Engine! If you’d like to see in-engine make sure to comment!

The code in node was first presented by Epic staff, Marc Audy, as code used in Fortnite.

I’ve fully implemented the code as well as making it user-friendly.

In particular I’ve presented a solution for ensuring you can spawn multiple instances of the same UE4 level, by giving you an “Instance Number” that you should increment each you spawn an instance of a level.

allows me to enable you to easily create as many uniquely translated and rotated instances of a level as you want!

is ideal for Dynamic Level Generation!


**Can Include Landscapes and Other Fancy Level Features!**

In my demo I included a landscape in my level "tile."

Level Scripting / Level Blueprint

You can also include level scripting that will run uniquely per level isntance!


**C++ Code For You**

Here's my implemenation of the code Marc Audy originally presented to the Community, exactly as it is in my Victory BP Library:



```


bool UVictoryBPFunctionLibrary::VictoryLoadLevelInstance(
	UObject* WorldContextObject, 
	FString MapFolderOffOfContent, 
	FString LevelName, 
	int32 InstanceNumber,
	FVector Location, FRotator Rotation)
{
    if(!WorldContextObject) return false;
	 
	UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject);
	if(!World) return false;
	//~~~~~~~~~~~
 
	//Full Name
	FString FullName = "/Game/" + MapFolderOffOfContent + "/" + LevelName;
	  
	FName LevelFName = FName(*FullName);
    FString PackageFileName = FullName;   
	
    ULevelStreamingKismet* StreamingLevel = NewObject<ULevelStreamingKismet>((UObject*)GetTransientPackage(), ULevelStreamingKismet::StaticClass());
 
	if(!StreamingLevel)
	{
		return false;
	}
	
	//Long Package Name
	FString LongLevelPackageName = FPackageName::FilenameToLongPackageName(PackageFileName);
	
	**//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Here is where a unique name is chosen for the new level asset
	//    Ensure unique names to gain ability to have multiple instances of same level!
	//	   <3**
	
	//Create Unique Name based on BP-supplied instance value
	FString UniqueLevelPackageName = LongLevelPackageName;
	UniqueLevelPackageName += "_VictoryInstance_" + FString::FromInt(InstanceNumber);
     
    //Set!
    StreamingLevel->SetWorldAssetByPackageName(FName(*UniqueLevelPackageName));
	**//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
	 
    if (World->IsPlayInEditor())
    {
        FWorldContext WorldContext = GEngine->GetWorldContextFromWorldChecked(World);
        StreamingLevel->RenameForPIE(WorldContext.PIEInstance);
    }
 
    StreamingLevel->LevelColor = FColor::MakeRandomColor();
    StreamingLevel->bShouldBeLoaded = true;
    StreamingLevel->bShouldBeVisible = true;
    StreamingLevel->bShouldBlockOnLoad = false;
    StreamingLevel->bInitiallyLoaded = true;
    StreamingLevel->bInitiallyVisible = true;
 
	//Transform
    StreamingLevel->LevelTransform = FTransform(Rotation,Location);
 
    StreamingLevel->PackageNameToLoad = LevelFName;
          
    if (!FPackageName::DoesPackageExist(StreamingLevel->PackageNameToLoad.ToString(), NULL, &PackageFileName))
    {        
        return false;
    }
  
	//~~~
	
	//Actual map package to load
	StreamingLevel->PackageNameToLoad = FName(*LongLevelPackageName);
	
	//~~~
	
    // Add the new level to world.
    World->StreamingLevels.Add(StreamingLevel);
     
    return true;
 }	


```