- Home /
Application.LoadLevel - Leaves behind multiple instances of scripts / objects
Hi All,
First of all thanks for all the helpful answers you people keep providing.
I am trying to restart my current level from a script attached to the Main Camera through: Application.LoadLevel (Application.loadedLevel);
Once I complete it, multiple instances of one script are running (There may be many I havent checked yet). For example, I use one script that subscribes to events from multiple scripts to decrease the "bullets left" and "score". When I noticed that they get decreased or increased by multiple numbers instead of having one step at a time, I printed using Debug.Log() for when I shoot. It prints twice after the first Application.loadLevel, then thrice after the 2nd reset and so on. Every time I restart the scene , the script is running that many times with that many decrease or increase in "Score" / "bullets left".
Theres one more script that has a null animator issue which I believe is due to the multiple instances issue as well.
Please help me with this. Everything looks like getting messed up due to multiple instances issue. ALSO I HAVE ABSOLUTELY NO DontDestroyOnLoad anywhere in my game. Pls help!
Edit: FYI: I use events and delegates. In the place from where I publish the event, when I use Debug.Log() to see if it publishes so many times, it only prints it once as expected. But the scripts which listens to these events :
void OnEnable()
{
BulletController.scoreUP += scoreIncrease;
BulletController.bulletCreated += bulletDecrease;
}
void OnDisable()
{
BulletController.scoreUP -= scoreIncrease;
BulletController.bulletCreated -= bulletDecrease;
}
listens and executes twice, or thrice or so on for every restart of scene.
Your answer
Follow this Question
Related Questions
Hey! how to connect two objects? So to make one? 3 Answers
how to get objects that are in some radius with the point in certain center 1 Answer
Selecting and unselecting objects with raycast 0 Answers
Memory Leak Adventures in Editor (3.4, lot of instantiated objects) 1 Answer
NullReferenceException: Object reference not set to an instance of an object 0 Answers