Hello,
I’m having a problem here and I’m truly clueless about how to solve it. My game runs just fine, no exceptions, when I hit the play button in the editor. However, once I run it’s executable the game throws a great amount of exceptions. Most of them are NullReferenceExceptions.
I tried to clean the project in Visual Studio, compile it again, replaced some ProjectSetting files for new ones of new projects, but still I can’t figure why so many exceptions are being throw.
Is there any difference between the build and the editor version of a project? What are the common causes to this?
Thanks in advance. Any kind of help is welcome!
Good day.
I had some similar issue some time ago (other Unity version but maybe is still the same)
The order of execution of all Awake methods was different in editor than in Build executable. The same with all On Enable, and Starts. (for example the Start method of ScriptA was executed before Start of ScriptB, but in Build, the Start of scriptB was executed before Start of scriptA)
So when some script gives information to another script, some objects was execturing it Start method before other object Start, causing some variables was not yet defined and giving the error.
I solved it making a clear order of definition of variables and assigning values using correctly Awake Onenable and Start.
What you can be sure is that all Awakes will be before all others methods, then all OnEnable, and then all Start. And finally the Updates.
Unity have also a way to configure what scripts will be executed before/after what other scripts, so you can configure it at your own.
–
Edit > Project Settings > Script Execution Order
–
Bye!