- Home /
What are the reason a scene don't reload the second time ?
Hello,
I have a problem with my project.
I start a scene, all run smoothly, ans if I try to start it again, it doesn't load anymore.
I tryed to find some reason, and one of them is forgetting event unreferencing, and use static variable.
But I quite sure now I checked all my lines and I don't find problem of unreferincg, every
GameManager.instance.OnStartGame += GameStart;
got is own
GameManager.instance.OnStartGame -= GameStart;
Before quitting the scene.
And also, all my static variable that get destroyed are like this
void Awake()
{
if (instance == null)
instance = this;
else if (instance != this)
Destroy(gameObject);
}
and got their own
instance = null;
when leaving the scene.
And finally, my DontDestroyOnLoad
void Awake()
{
if (instance == null)
instance = this;
else if (instance != this)
Destroy(gameObject);
DontDestroyOnLoad(transform.gameObject);
}
I don't think there is a miss, I will still continue to check, but is there another possible reason, or a easier way to troubleshoot?
Thanks
How do you restart scene? Can you show code? And when OnStartGame is called?
I do not restart scene, I go from Scene $$anonymous$$enu to Scene level 01, than back to menu, and when I want to reenter Level01 with the same manipulation as the first time, it doesnt do anything
public void LoadScene(string LevelName) { Scene$$anonymous$$anager.LoadScene(LevelName); }
for the GameStart I want to do it on the first frame after Start so for the moment I use a bool and do this
void Update()
{
if (!gameStarted)
{
Game$$anonymous$$anager.instance.StartGame();
gameStarted = true;
}
}