Page 1 of 1

Invector restart after death not working

Posted: Fri Nov 12, 2021 9:12 am
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

Re: Invector restart after death not working

Posted: Fri Nov 12, 2021 9:28 am
by Tony Li
Hi,

Did you follow the steps in Respawning and Reloading Saved Games?

Re: Invector restart after death not working

Posted: Fri Nov 12, 2021 9:38 am
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

Re: Invector restart after death not working

Posted: Fri Nov 12, 2021 11:13 am
by hrohibil
It works.

But it restarts ASAP..
Can i delay 2 sec so i can see the death animation?

Re: Invector restart after death not working

Posted: Fri Nov 12, 2021 11:20 am
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);
    }

Re: Invector restart after death not working

Posted: Fri Nov 12, 2021 12:07 pm
by hrohibil
It worked.

You are truely awesome Toni..

Cheers

Re: Invector restart after death not working

Posted: Fri Nov 12, 2021 1:30 pm
by Tony Li
Glad to help! :-)