I cut up a map with world partition. A Twon portal (Actor) is placed inside Area1. Put a LevelInstance in Area9. LevelInstance has a standard Level (with floor and PlayerStart) and the player’s starting position is in Area A1
When the player is within range of the portal, a specific button is pressed to start teleporting.
Question 1: How do I know if the LevelInstance for the transfer destination is in a region on the map?
Q2: How to switch to LevelIntance if the transport area is within an area of the map
Sorry, my English is not good, I use Google Translate, please forgive me for the inconvenience
I’m not sure if you looking for a way in Blueprint or C++ - I have a routine here that looks through the World Partitions for level instances at a certain location:
FSphere BrushSphere;
BrushSphere.Center=FVector(0,0,0); // set this to your position
BrushSphere.W=10000.0f; // radius
const bool bEnsureIsGWorld=true;
UWorld* World=GEditor?GEditor->GetEditorWorldContext(bEnsureIsGWorld).World():nullptr;
const FBox BrushSphereBounds(BrushSphere.Center-BrushSphere.W,BrushSphere.Center+BrushSphere.W);
UClass* actorClass=ALevelInstance::StaticClass();
UActorPartitionSubsystem* actorSubsystem=World->GetSubsystem<UActorPartitionSubsystem>();
const uint32 GridSize=actorClass->GetDefaultObject<APartitionActor>()->GetDefaultGridSize(World);
const UActorPartitionSubsystem::FCellCoord MinCellCoords=UActorPartitionSubsystem::FCellCoord::GetCellCoord(BrushSphereBounds.Min,World->PersistentLevel,GridSize);
const UActorPartitionSubsystem::FCellCoord MaxCellCoords=UActorPartitionSubsystem::FCellCoord::GetCellCoord(BrushSphereBounds.Max,World->PersistentLevel,GridSize);
for(int32 z=MinCellCoords.Z;z<=MaxCellCoords.Z;z++) {
for(int32 y=MinCellCoords.Y;y<=MaxCellCoords.Y;y++) {
for(int32 x=MinCellCoords.X;x<=MaxCellCoords.X;x++) {
UActorPartitionSubsystem::FCellCoord CellCoords(x,y,z,World->PersistentLevel);
const FVector Min=FVector(CellCoords.X*GridSize,CellCoords.Y*GridSize,CellCoords.Z*GridSize);
const FVector Max=Min+FVector(GridSize);
FBox CellBounds(Min,Max);
if(CellBounds.Intersect(BrushSphereBounds)) {
const bool create=true;
if(auto PartitionActor=actorSubsystem->GetActor(actorClass,CellCoords,create)) {
ALevelInstance* levelInstanceActor=Cast<ALevelInstance>(PartitionActor);
if(levelInstanceActor) {
// process the levelinstance here
}
}
}
}
}
}
Once you have that Actor, you should be able to load it and “SetCurrent”.
Sorry, an error occurred while executing the following line of code
const uint32 GridSize = actorClass->GetDefaultObject()>GetDefaultGridSize(World);
The reason is to execute this line of code: DEFINE_VTABLE_PTR_HELPER_CTOR(ALevelInstance);
My mistake - it’s been a long day! - the code is from a routine I use for finding the foliage actors - I had assumed that it would be possible to get a CDO of a partitionactor from other things, but it looks like it’s only in foliage and PCG.
I just had a look on google, but wasn’t able to find anything useful.