I’m trying to get movable objects to become part of the level they’re in when it unloads so they don’t just fall into the void (I’m using world composition if it matters). As far as I can find it can only be done with C++ so I started using it and created a LevelScriptActor class and I’m trying to do this:
void AMyLevelScriptActor::EndPlay(const EEndPlayReason::Type EndPlayReason) {
this->MoveActors();
Super::EndPlay(EndPlayReason);
}
void AMyLevelScriptActor::MoveActors()
{
ULevelStreaming *ThisLevelStreaming = FLevelUtils::FindStreamingLevel(this->GetLevel());
ULevel *LoadedLevel = ThisLevelStreaming->GetLoadedLevel();
//FBox LevelBounds = ALevelBounds::CalculateLevelBounds(LoadedLevel);
FBox LevelBounds = ThisLevelStreaming->GetStreamingVolumeBounds();
FString debug = ThisLevelStreaming->GetWorldAssetPackageName() + " - " + LevelBounds.Min.ToString() + " - MAX " + LevelBounds.Max.ToString();
if (GEngine)
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, debug);
This prints the name of the level that’s unloading correctly but both Min and Max are 0,0,0 so my objects will never be inside it, whether I use the commented out LevelBounds or the other one.
I learned most of this from these links: