Hi Guys,
I’m having a bit of an issue here. When clicking on “Try again” button the level doesn’t restart on Level 1 scene but loads the splash screen. I checked everything and came up with a conclusion that it must be about the currentSceneIndex. For some reason, it must be pointing to the value of 0. I don’t know why. Does anybody have a clue?
Does the level manager persist, dontdestroyonload stuff? Also maybe throw a debug out that shows the current level index
Used Debug, and when I hit “play” it shows currentlevelIndex = 2 (as it should). Threw a debug in the Restart method and it showed “0”.
public void RestartScene()
{
Debug.Log(currentSceneIndex);
SceneManager.LoadScene(currentSceneIndex);
}
So I don’t know what’s going on, but starting this method changes the index.
Well that is odd. Take a look at this, https://docs.unity3d.com/ScriptReference/SceneManagement.LoadSceneMode.html , And load the scene single and let’s see
Added this line:
public void RestartScene()
{
Debug.Log(currentSceneIndex);
SceneManager.LoadScene(currentSceneIndex, LoadSceneMode.Single);
}
and the effect is the same. Don’t know what else I can do.
Ok, instead of calling the variable, call the function to return the index, I suspect the same result but worth trying.
Did you mean smth like this:
public void RestartScene()
{
Debug.Log(currentSceneIndex);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
here, works perfectly. If I put in the brackets “2” oraz “Level 1”, it works as well.
Thanks for your help Bryant! I can leave it for now, but if you have any other idea, I’d experiment gladly. Cheers!
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.