Seemingly undefined behavior of TSet

I am working on procedurally generating a building’s interior. I have a custom c++ “Room” actor, which can generate several room variations. Each room has child “Exit” actors attached to each doorway, so that during generation, each newly generated room aligns one of its Exits to the Exit of a different room, making the two rooms connect perfectly at their doorways.

This all works fine, but the rooms are densely packed and often overlap into one another, which obviously shouldn’t happen. To solve this, I tried to make use of the GetOverlappingActors function in c++, to check if a newly spawned room was overlapping, and if so, to simply delete that room and stop generating in that direction. This is where completely incomprehensible issues began occuring. Simply calling the GetOverlappingActors function and not even doing anything with the result causes all my room actors to take on seemingly random rotations.

Here is what generation looks like WITHOUT calling GetOverlappingActors:

And here is what generation looks like WITH a call to GetOverlappingActors:

The only code I added between these two pictures is:

TSet<AActor*> overlapRoomActors;
NewRoom->GetOverlappingActors(overlapRoomActors, ARoom::StaticClass());

I figured at first this must be related to the collision settings for the room, with the rooms automatically moving to try and “uncollide” or something. But I double checked collision settings, and Rooms are set to generate overlap events with each other, but not block each other, so this doesn’t really make sense. Weirder still, GetOverlappingActors() gives me an empty list (even when overlap is clearly happening).

Finally, for the weirdest part, I seemingly narrowed down the problem to JUST the use of TSet. Removing the call to GetOverlappingActors, the same random rotation of rooms occurs with almost any function acting on the initialized TSet. For example, replacing the above code block with either of the following two causes the exact same behavior:

TSet<AActor*> overlapRoomActors;
overlapRoomActors.Add(NewRoom);
TSet<AActor*> overlapRoomActors;
int x = overlapRoomActors.Num();
UE_LOG(LogTemp, Warning, TEXT("overlaps: %d"), x);

But strangely in the above code, removing last line with the log causes room generation to go back to normal again.

WHAT ON EARTH COULD CAUSE THIS?? I’m actually going crazy.