Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Properly reloading scene _ NEED URGENT HELP

Discussion in 'Scripting' started by Hapciupalit, Aug 11, 2017.

  1. Hapciupalit

    Hapciupalit

    Joined:
    Apr 24, 2015
    Posts:
    103
    Hey guys,
    I'm in a bit of a rush because I should have done a release a few hours ago and I'm still struggling with a thing I cannot understand.

    I created an object in a scene and then when I go to the main menu and go back to this scene my objects are still there even if there should not be created yet.

    Code (CSharp):
    1. public GameObject toInstantiate;
    2.  
    3. public CreateObject(){
    4.   GameObject temp = Instantiate(toInstantiate) as GameObject;
    5. }
    this is how I create the object.

    Please help me, how can I reload the scene from 0?
     
  2. listener

    listener

    Joined:
    Apr 2, 2012
    Posts:
    179
    For start you can check two things.

    - Make sure objects are not already in the scene
    - When is CreateObject() called if its by some script on startup then they would be in scene as soon as it loads.

    I would suggest putting breakpoint in CreateObject method and just check what is calling it.
     
    Hapciupalit likes this.
  3. Hapciupalit

    Hapciupalit

    Joined:
    Apr 24, 2015
    Posts:
    103
    Thank you... I changed the way it was called and now it's working