I’m working on a procedural level script. I can’t call CreaeInstance() in code so i have to split my code into two blocks. One for selecting the level from an array that is populated inside of blueprint and another function that sets the level properties such as bShouldBeLoaded, bShouldBeVisible, and the level transform.
So far I have to code working in the sense that it spawns a level without crashing but the problem here is that it goes right to the end of the For Loop and only spawns the last iteration. I will post my code and Blueprints I’m hoping someone will be able to tell me how to “pause” the for loop so it does each iteration properly.
CPP:
void AProceduralLevelScript::GenerateLevel(ULevelStreaming* &LevelToStream, FString& InstanceName, int32& x, int32& y)
{
for(int32 x = 0; x <= GridSizeX; ++x)
{
for(int32 y = 0; y <= GridSizeY; ++y)
{
int32 randInt = FMath::RandRange(0, LevelNames.Num() - 1);
LevelToStream = UGameplayStatics::GetStreamingLevel(GetWorld(), LevelNames[randInt]);
InstanceName = FString::FromInt(x) + FString::FromInt(y);
}
}
}
void AProceduralLevelScript::SetLevelProperties(ULevelStreaming* level, int32 x, int32 y)
{
level->bShouldBeLoaded = true;
level->bShouldBeVisible = true;
level->LevelTransform = FTransform(FVector((GridSizeX * LevelSizeX / 2) - LevelSizeX * x, (GridSizeY * LevelSizeY / 2) - LevelSizeY * y, 0.0f));
}