Invector restart after death not working

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
hrohibil
Posts: 368
Joined: Thu Nov 04, 2021 12:50 pm

Invector restart after death not working

Post by hrohibil »

Hi Toni

If I play game from the actual level and die then it will restart and work as intended.

But when I start game from main menu and then when I die, game don’t restart. It just continues with my player dead on the ground
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Invector restart after death not working

Post by Tony Li »

Hi,

Did you follow the steps in Respawning and Reloading Saved Games?
hrohibil
Posts: 368
Joined: Thu Nov 04, 2021 12:50 pm

Re: Invector restart after death not working

Post by hrohibil »

No I did not.
So I basically create a script and add this to it.
Nice and easy.

As I understand it will respawn from the saved game I loaded from?

If for some reason there is no saved game I need to put some code in the “else” statement.

Sorry Toni I am not that good with code, do you have an example how to display the menu/ load ?
Like you suggest in the comments

Cheers
hrohibil
Posts: 368
Joined: Thu Nov 04, 2021 12:50 pm

Re: Invector restart after death not working

Post by hrohibil »

It works.

But it restarts ASAP..
Can i delay 2 sec so i can see the death animation?
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Invector restart after death not working

Post by Tony Li »

Yes, you can modify the ReloadOnDeath method to do that. Maybe something like:

Code: Select all

    private void ReloadOnDeath(GameObject player)
    {
        if (SaveSystem.HasSavedGameInSlot(checkpointSaveSlot))
        {
            Invoke(nameof(LoadCheckpoint), 2); // Load from checkpoint after 2 seconds.
        }
        else
        {
            // Show load game menu? Go to main menu? etc. (Add your code)
        }
    }
    
    private void LoadCheckpoint()
    {
            SaveSystem.LoadFromSlot(checkpointSaveSlot);
    }
hrohibil
Posts: 368
Joined: Thu Nov 04, 2021 12:50 pm

Re: Invector restart after death not working

Post by hrohibil »

It worked.

You are truely awesome Toni..

Cheers
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Invector restart after death not working

Post by Tony Li »

Glad to help! :-)
Post Reply