Unity 3D [C#] - How to properly reset a scene

I have a problem when I try to reset a scene. It doesn't seem to run, I have a script (of all scripts that have Awake and Start methods on that scene) that on the Awake method starts a coroutine, but when reseting the scene it doesn't even run it. I've read that it may be a problem of using the DontDestroyOnLoad method, but that doesn't seem to solve the problem since that script on the start takes a lot of references of objects that are only on the scene that I want to restart. I don't use any static variables on any script.

I made an unitary test trying to restart a scene with just one object and one script attached, on its Start method it also starts a coroutine but even in that test it doesn't even run the coroutine.

Here's the script of the unitary test:

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

{
void Awake()
{
}
//Scene scene;
// Use this for initialization
void Start()
{
//scene = SceneManager.GetActiveScene();
useStartCoroutine();
}

void useStartCoroutine()
{
}

{
yield return new WaitForSeconds(3);
}
}

• Try using Scene scene = SceneManager.GetActiveScene(); SceneManager.LoadScene(scene.name); instead of the name. – John Hamilton Dec 9 '16 at 21:53
• that would be a solution for the case on which I would try to reset the scene from the active scene. But what happens if I want so replay the scene from another scene. Should I store the scene in a variable then? – LifGwaethrakindo Dec 9 '16 at 21:56
• There could be many methods to achieve this. See: gamedev.stackexchange.com/questions/133872/… – John Hamilton Dec 9 '16 at 21:58
• Are you sure that you have added scene in Build section? and i prefer you using indexes of scenes instead of names, just to be sure. – Nick Dec 9 '16 at 22:12
• Yeah, the scene is added on build settings, when I load the scene for the first time it runs normal. The second time I try to load it its when it doesn't run... – LifGwaethrakindo Dec 9 '16 at 23:03

...the Awake method starts a coroutine, but when reseting the scene it doesn't even run it.

The Awake method is only called when a script is first loaded. Because your script has DontDestroyOnLoad (which you don't need to put in Start because you already have it in Awake), it will be carried over to any new scene that you load, and it will not be loaded again, so Awake will not be called again.

What you want is a method that subscribes to the SceneManager.sceneLoaded event:

private void OnEnable()
{
}

private void OnDisable()
{

This code will be called between the Awake and the Start methods when loading a scene.
A bit unrelated, but it's important to note that, because your original code has DontDestroyOnLoad, if you switch from a scene that has your LoadingSceneController object within it to a different scene, and then switch back to that scene, it will create a second instance of your LoadingSceneController object. You can fix this by spawning your LoadingSceneController object through code only once (if it doesn't already exist), or adding some code at the beginning of your script's Awake that will destroy its gameObject if another object with that script already exists.