Restart Current Level ((Help))

I have been searching everywhere for a tut on restarting level on death, but none of them work good now.
I am not looking to save game, just force player to replay level if they die in it.

Longer way to do it is make several enemies by level. (Too much).

Should be a way to get current level the player is on, right?

Thanks guys for all your help.

Wanted to add, my main point is to use a you died widget and have the button restart which ever current level the player is on. Not sure how to do the vars for that. Try several methods, but a lot of them crash the game or just don’t function.

Where is that to be applied? Game Inst, PlayerBP, the widget? Thanks

Also, Is this to be used on death? I have a death function in my playerBP. But I made enemies for the game, used the same enemies throughout the game as well. Can’t say if enemy kills me, go to level ??. It would take me back to Level 1 automatically.

This is the problem in the first place, this would require me to have multi widgets to say “Restart Level” Wont work that way. That requires each enemy to be individual on it’s ability to cause action after death. Hence way I am looking for a variable set up to figure out what level the player is on and restart that one.

Hello NuHabitStudios,

Simplest way to do this would be to use an “Execute Console Command” node and use restartlevel as the command.

This will restart the current level.

Hope that helps,

Really up to you (same behaviour no matter where it’s called). If you’re using the “Restart level” UMG button/widget executing it there makes sense.

Here is what I am currently trying to do.

My widget has a var from the game Instance, to select what current level the player is on. My issue is what to do next from LevelBP, PlayerBP?

Not Sure, but I might have answered it myself. I tried this and it seem to work not sure if it is correct though.

Got the image below from the following link:
[Unreal Engine 4 Tutorial: How to reload the current level][1]

On a different note, for all intent and purpose this is going to do the same thing as putting ‘RestartLevel’ in an ‘Execute Console Command’ node like suggested by O.

2 Likes

This worked perfectly!!

1 Like

EDIT: I’m using UE5.1
So I was working on the save-load system in my game and somehow this only worked when;

  • I hit the little triangle under the “Get Current Level Name” (to expand the node) and,
  • Unmarked the “Remove Prefix String”
    Before un-marking the remove prefix string when I tried to use this from “Restart the Level” in the pause menu, it was sending me back to the main menu level. I know the original question is not looking for the save load system but when I searched google this is the first post that come up so I think it may help others :saluting_face:
    And @Arceyo just to be a little geek :laughing: I tried both of them to check whether or not one of them works, ‘Execute Console Command’ was working fine whereas ‘Get Current Level Name’ didn’t. So I assume that using ‘Execute Console Command’ does not remove the prefix

You can also do this now.


	GetWorld()->ServerTravel(TEXT("?restart"), false); // has to be relative
	// taken from Engine\Source\Runtime\Engine\Private\PlayerController.cpp:1887

i assume you can also do it on bps, but haven’t tested it.