[World Composition] Let spawned actor check if the sub-level is loaded

Hi!
I have mutliple sublevels in World Composition, with a dedicated server spawning items all over the world.
I simulate physics on the items at spawn, but when the sub-level is too far away the landspace isn’t rendered. This means the items spawned in that level fall to the ground.

So when I spawn an item I want to check if the level I spawned in is loaded by the player.

Is there any way to accomplish this?

I tried to override the base class for ULevel but ran into a bunch of problems, it seems that class isn’t meant to be overridden.

Thanks in advance!

Update

Using a work-around I’m not super proud of, but works for whomever suffers from the same problem.

Override GameInstance class: MPGameInstance;
Override LevelScriptActor class: MPLevelScriptActor;

Use ENUM EMPSubLevels to differentiate the different sublevels

Reparent level blueprint in sub levels in World Composition to MPLevelScriptActor.

On BeginPlay and EndPlay call function in parent LevelScript: SetSubLevelAvailability(EMPSubLevels SubLevel, bool bIsAvailable);

In MPLevelScriptActor:



void AMPLevelScriptActor::SetSubLevelAvailability(EMPSubLevels SubLevel, bool bIsAvailable) {
	UMPGameInstance* MPGameInstance = Cast<UMPGameInstance>(GetWorld()->GetGameInstance());
	if(MPGameInstance ) {
		MPGameInstance->SetSubLevelAvailability(SubLevel, bIsAvailable);
	}
}


In MPGameInstance (which is persistent across levels) the implementation of SetSubLevelAvailability simply records which levels are loaded and which aren’t.
This way each spawned item can check the GameInstance if it’s safe to simuate physics in its current level.

Since each item is spawned in PersistentLevel, however, I force my level designer to assign the item spawner the UMPSubLevel enum so it knows which sublevel it belongs to at spawn :slight_smile: