- Home /
EventSystem causes a NullRef error on restarting a level
Hi. I'm having a problem just since installing 4.6, that I didn't have with 4.6 Beta. I'm in the testing phase of my game so for convenience, instead of restarting a scene by clicking play twice, I have the following in a script:
//FOR TESTING ONLY
if (Input.GetButton ("Restart"))
{
Application.LoadLevel(Application.loadedLevel);
}
"Restart" is set to 'r' in the Input manager. I'm using UI elements in my levels, so I have an EventSystem in each scene. Before the newest install, I could restart perfectly with no errors but now I get the following when I press it:
I don't know what to do about it. I tried putting the EventSystem on a gameobject and instantiating that object at the start of the level, and I also tried putting it on an object that uses "DontDestroyOnLoad(this.gameobject)" but even then it won't restart without an error.
Right now the event system is in the scene's hierarchy (not instantiated), IS destroyed on load, and that error is thrown up as soon as I press "Restart", but it'll run the initial level just fine, until I restart. Any ideas?
Thanks Kevin
nobody else have this? I've created blank new projects and still get it, so I don't think I should be the only one with it..
Is the code posted there the line that causes the exception?
Also, if you can do this with a blank project and one script, could you paste that script to pastebin or something like that?
The line that causes the error is that one (or whatever similar version I use to reload the level within runtime). Can also get it with Application.LoadLevel(0) for example. And it's not that the line causes the error, but when the scene is reloaded successfully, the error is there because the new Event System in the scene doesn't seem to know what it's doing.
In a blank project I can replicate the error with just a single UI button in the scene, and I restart by either clicking the button or pressing the 'r' key. Same error. Pastebin here for the full script in a new project.
Answer by unimechanic · Dec 09, 2014 at 03:52 PM
In a blank project I can replicate the error with just a single UI button in the scene, and I restart by either clicking the button or pressing the 'r' key. Same error.
Please submit a bug report with the minimal sample project that you created:
Your answer
![](https://koobas.hobune.stream/wayback/20220613172640im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity 4.6 UI Events Stop working 0 Answers
EventSystem - all touches have the same ID 3 Answers
4.6 UI Change what 'Spacebar' is doing by default 1 Answer
UI Navigation on Fire TV 1 Answer