Why is ULevelStreamingDynamic::GetLoadedLevel() returning nullptr?

Hello! I’ve been attempting to use level streaming for my game, but I’ve come across an issue. First, I selected a random level from a data table. After I loaded that level in, I called the level instance’s GetLoadedLevel() which returned a nullptr. This is a problem, since I am attempting to get a specific actor from that level instance. The level instance loads into the editor just fine, so I’m not sure what’s wrong. Is there something I’m missing? If anyone needs more information, please ask.

// Get random level
TileID = Seed.RandRange(1, RoomsTableLength);
RoomInformation = RoomsTable->FindRow<FRoomInformation>(RoomsNames[TileID - 1], "");

// Load the level instance
RoomLevel = ULevelStreamingDynamic::LoadLevelInstanceBySoftObjectPtr(GetWorld(), RoomInformation->Level, FTransform(FRotator(0,0,0), FVector(0,0,0), FVector(1,1,1)), bIsLevelLoadSucessful);

// GetLoadedLevel() returns nullptr
check(RoomLevel->GetLoadedLevel());
if (ensure(bIsLevelLoadSucessful and RoomLevel))
{
     RoomLevel->OnLevelLoaded.AddUniqueDynamic(this, &ADungeonManager::HandleRoomLoaded);
}

Turns out I needed to wait for the level to load, so I implemented this small check and continued the rest of the logic in the handler.

EDIT: Nevermind, I jumped the gun. The level never actually loads, so OnLevelLoaded doesn’t get called.

EDIT2: Okay. This does in fact work. I just did not make HandleRoomLoaded a UFunction.

UFUNCTION()
void HandleRoomLoaded();

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.