0
\$\begingroup\$

I am using

SceneManager.LoadScene(SceneManager.GetActiveScene().name);

to reload my current scene in unity , but when i run the game ,in hierarchy lots of scene are appearing. Also if i do some editing, i can not save the scene any more. unity is giving and error "Overwriting the same path as another open scene is not allowed". I am new to game development. I would appreciate any help. image

\$\endgroup\$
  • \$\begingroup\$ You need to make sure you call the function only once when you want to. It appears you are calling it multiple times, in Update() or somewhere that gets called multiple times. \$\endgroup\$ – Lasse Sep 13 '17 at 6:08
  • \$\begingroup\$ I am using it only when user collide with an enemy object void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Enemy") { makeDead (); } } \$\endgroup\$ – Jayakrishnan Sep 13 '17 at 6:15
  • \$\begingroup\$ makeDead has SceneManager.LoadScene(SceneManager.GetActiveScene().name); \$\endgroup\$ – Jayakrishnan Sep 13 '17 at 6:16
1
\$\begingroup\$

This might be solution to your problem, but I can't say for certain.

This is what I usually do to prevent collisions from calling the same function multiple times:

bool dying = false;
bool dead = false;

void Update()
{
    if(dying && !dead)
    {
        dead = true;
        makeDead();
    }
}


void OnCollisionEnter2D(Collision2D coll) 
{ 
    if (coll.gameObject.tag == "Enemy") 
    { 
        dying = true;
    } 
}
\$\endgroup\$
0
\$\begingroup\$

Error: Multiples "loading or is not loaded" scenes in the editor hierarchy. Error: "Overwriting the same path as another open scene is not allowed".

Add LoadSceneMode parameter.

SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);

Update: Better, but same issue. This could be a Unity bug. This image is after stop player:

enter image description here

\$\endgroup\$

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.