How to get current running level's name?

Is there a simple and elegant way to get current level name?

If there is not a way out, I have to hardcoded the level name. I only need to restart the game.
But AGameMode::RestartGame() will cause crash when exit PIE.

So I found the only way will not crash is using UGameplayStatics::OpenLevel to open the current game level.

It will cause problem when I change the level’s name. The problem still exists using config file.(When you forget change level name in config file it has same effect as hardcoded the level name in C++ or blueprints)

I just answered this on your AnswerHub version.

Execuse me. I found it.
GetWorld()->GetName() will return the current map name.

Sorry to bother you guys.

2 Likes

But it seems there is no easy way to do it in Blueprints

UGamePlayStatics::OpenLevel(this, GetWorld()->GetName(), false);

But there still exists a problem by doing this to restart a level. You need to save currrent Level first. It will load the level last saved.
It can not load the level is editing but not saving it.

Actually to get LevelName on BP is “GetCurrentLevelName” node.
GetCurentLevelName

:slight_smile:

1 Like

Oh my didn’t knew Im answering 6 years later :joy:

4 Likes