I’m trying to place rooms into a persistent level using level streaming. When the rooms are loaded in I check if the triggerbox inside of the room is overlapping with any of the triggerboxes that are already in the level. This however always returns false and when I check if the triggerbox is overlapping anything it returns 0 other actors. Using blueprints this works so I don’t know why it doesn’t work here.
It gets all the correct triggerboxes but doesn’t find any overlaps.
void ALevelManagerCPP::BeginPlay()
{
Super::BeginPlay();
World = GetWorld();
BuildGame();
}
void ALevelManagerCPP::BuildGame()
{
LoadStartingRoom();
LoadRoomsTypeA();
}
void ALevelManagerCPP::LoadStartingRoom()
{
FLatentActionInfo LatentInfo;
RoomLocation = FVector(0,0,0);
RoomRotation = FRotator(0,0,0);
bool Success;
ULevelStreamingDynamic::LoadLevelInstance(World, StartingRoomName, RoomLocation, RoomRotation, Success);
UGameplayStatics::FlushLevelStreaming(World);
}
void ALevelManagerCPP::LoadRoomsTypeA()
{
TArray<FString> BackupNames = RoomNamesTypeA;
int MaxIndex = RoomNamesTypeA.Num();
while(MaxIndex > 0)
{
FLatentActionInfo LatentInfo;
UGameplayStatics::GetAllActorsOfClass(World, ATriggerBox::StaticClass(), Layout);
UGameplayStatics::GetAllActorsOfClass(World, AExitPointCPP::StaticClass(), OpenExitPoints);
int RoomIndex = FMath::RandRange(0, RoomNamesTypeA.Num() - 1);
FString LevelToLoad = RoomNamesTypeA[RoomIndex];
int ExitIndex = FMath::RandRange(0, OpenExitPoints.Num() - 1);
AActor* ChosenExit = OpenExitPoints[ExitIndex];
RoomLocation = ChosenExit->GetActorLocation();
RoomRotation = ChosenExit->GetActorRotation();
bool Success;
//UGameplayStatics::LoadStreamLevel(World, LevelToLoad, true, true, LatentInfo);
ULevelStreamingDynamic::LoadLevelInstance(World, LevelToLoad, RoomLocation, RoomRotation, Success);
UGameplayStatics::FlushLevelStreaming(World);
TArray<AActor*> LevelToLoadLayout;
UGameplayStatics::GetAllActorsOfClassWithTag(World, ATriggerBox::StaticClass(), FName(*LevelToLoad), LevelToLoadLayout);
bool Overlaps = false;
for (auto TriggerBoxLevel : LevelToLoadLayout)
{
for (auto TriggerBoxWorld : Layout)
{
if(TriggerBoxWorld->IsOverlappingActor(TriggerBoxLevel))
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "debug msg");
Overlaps = true;
break;
}
}
}
if(Overlaps)
{
UGameplayStatics::UnloadStreamLevel(World, FName(*LevelToLoad), LatentInfo, true);
UGameplayStatics::FlushLevelStreaming(World);
}
else
{
MaxIndex--;
RoomNamesTypeA.RemoveAt(RoomIndex);
}
}
}