When my game ends I want it to automatically restart from the beginning so that the whole scene repeats itself. How do I do that in Unity 3D?

Please refer this link for clarification.

  • \$\begingroup\$ I think SceneManager.LoadScene(0); might interest you \$\endgroup\$ – Foxwarrior Oct 10 at 3:19
  • 1
    \$\begingroup\$ Questions on Stack Exchange should be as self contained as possible. Very few users are going to go off-site to check out your project in order to answer your question. Please consider making a minimal, complete, and verifiable example instead. \$\endgroup\$ – Pikalek Oct 10 at 3:35

To restart your current scene, you need current scene index or name. And once you have the current scene index or name then just reload it. Here the example that how i done it:

public void RestartCurrentScene()
     int currentScene = SceneManager.GetActiveScene().buildIndex;

Add this to the very top section of the script. As it is required by "SceneManager".

using UnityEngine.SceneManagement;

I hope this will help...


you can use this code:

    UnityEngine.SceneManagement.SceneManager.LoadScene( UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
  • \$\begingroup\$ This looks equivalent to Swati's answer, but with less explanation and with the added expense of string lookups. Can you clarify why you feel it's an improvement over the existing answer? \$\endgroup\$ – DMGregory Oct 10 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.