Break All LevelInstances
Introduction
This function recursively breaks all LevelInstances in the scene.
Implementation
UFUNCTION(BlueprintCallable, meta=(WorldContext="WorldContextObject", CallableWithoutWorldContext))
static void BreakAllLevelInstance(UObject* WorldContextObject);
void UMyBlueprintFunctionLibrary::BreakAllLevelInstance(UObject* WorldContextObject)
{
if(WorldContextObject)
{
TArray<AActor*> OutActor;
bool Stop;
do
{
Stop = true;
OutActor.Empty();
UGameplayStatics::GetAllActorsOfClass(WorldContextObject, ALevelInstance::StaticClass(), OutActor);
for(const auto& It : OutActor)
{
if(ILevelInstanceInterface* LevelInstance = Cast<ILevelInstanceInterface>(It))
{
if(!LevelInstance || !Cast<AActor>(LevelInstance))continue;
UE_LOG(LogTemp, Log, TEXT("BreakLevelInstance::%s"), *It->GetPathName());
WorldContextObject->GetWorld()->GetSubsystem<ULevelInstanceSubsystem>()->BreakLevelInstance(LevelInstance, 1);
Stop = false;
}
}
}
while (!Stop);
}
}