How to restart level when player dies

Hey guys. So when the player dies in my game so far, the level does not restart it just continues where it left off.

In udk I had it in kismet where after the player died the level would reset. I am wondering on how to do this in ue4. I am sure it has to be done in blueprints, but I have an idea on how to do it, am still 100 percent lost. Any ideas on how to do this would be great!

Thanks

Jason

1 Like

Hey,

There are multiple ways you could handle this, take a look at this post:

-W

As this is the first Google result I found for level restarting when I was searching, I feel it’s imperative to mention here what I just accidentally found out: you can now simply use an “Execute Console Command” node with the command “RestartLevel.”

hmm when I use console command RestartLevel, nothing happens… Why dosen’t it work?

1 Like

For anyone looking to do this via c++:
UGameplayStatics::OpenLevel(this, FName(*GetWorld()->GetName()), false);

4 Likes

hi~
I think you can call the RestartLevel on PlayerController in C++ or Blueprint.

See the source code at class APlayerController:
/** Restarts the current level */
UFUNCTION(exec)
virtual void RestartLevel();

1 Like

Don’t excactly can recall right now, but there is an console command to just load the level, if your game ends just excecute it.

so use the node “Excecute console command” and use one of these commands
I think it was OpenLevel (Levelname) you need to run this on a server if you are doing multiplayer
and RestartLevel or something like that this one will only work on singleplayer

There also is a node to load a level, but I haven’t tried it and I am not sure if it is from a plug in or not.

Using the console command is not the recommended way. I have provided how to do it in c++ in my answer bellow. This post http://www.unrealidiot.com/how-to-reload-current-level-in-unreal-engine-4 shows how to do it in blueprint. It is pretty much the same thing.

  • Get the current level name
  • Call OpenLevel passing the level name
2 Likes

There’s a RestartGame BP node to reload the current level. You just need to pass it the current game mode: GetGameMode.

In 2020 it’s still works! ty!

just use open level command and give the level name you want to open

I did it this way:

327539-restartlevel.png

1 Like
1 Like

Hi, after restarting level with this method I have an issue: “Pure virtual function being called”, then project crashes

Well it says it’s Virtual, hence without any definition.

Virtual functions can have a definition. Even pure virtual functions can have a definition, but they don’t have to. If you somehow call a pure virtual function with no definition, then the runtime exception will happen.

Typically, this happens if you attempt to call the superclass function in some way that’s not caught by the compiler/linker (a direct reference will cause a linker error, but a constructor or destructor reference may cause it to happen.)

#include <iostream>

using namespace std;

void func(struct Foo *f);

struct Foo {
    Foo() { cout << "Foo::Foo()" << endl; }
    virtual ~Foo() { cout << "Foo::~Foo()" << endl; func(this); }
    virtual void pure_impl() = 0;
    virtual void pure_not_impl() = 0;
};

void Foo::pure_impl() { cout << "Foo::pure_impl()" << endl; }

struct Bar : Foo {
    Bar() { cout << "Bar::Bar()" << endl; }
    ~Bar() { cout << "Bar::~Bar()" << endl; pure_not_impl(); }
    void pure_impl() override { cout << "Bar::pure_impl()" << endl; Foo::pure_impl(); }
    void pure_not_impl() override { cout << "Bar::pure_not_impl()" << endl; }
};

void func(Foo *f) {
    f->pure_impl();
    f->pure_not_impl();
}

int main() {
    Bar b;
    func(&b);
    return 0;
}

1 Like