- Home /
Getting a null reference exception in build but not in editor
Hello im getting a null reference exception in build but not in editor why is this happening I have made some public variables like| public GameObject test; |and then in the inspector I have linked then up and have not left them blank. The game works in the editor and does everything it needs to do but when I build to anything like pc and android they both give a null reference exception. How can I fix this issue?
Answer by frederikedel · Oct 22, 2020 at 11:01 AM
Without knowing much of how all things are setup, my general tip when something is null in a build, but not in the editor is an order of operation errors. After that, there can be platform specific stuff, but based on what you're saying, wouldn't surprise me if you have stuff just being done in a different order then you expect.
You need to make sure that scripts are executing in the proper order. Is your array populated before you try to access values? Are the parts of the array setup before you try to access them?
Remember that if you have several scripts with Awake, there is no way of knowing their order. Same with Start. Unless you setup the script execution order part. Another solution: Another poster recently had a problem that occurred only in builds and not in the editor, and it turned out that they were using Unity cloud builds, and the Unity version for the cloud builds didn't match what they were running locally.
Answer by PuzzleBuilder · May 11 at 10:38 PM
I had an issue that only showed up in the build that was related to which collider was tripped first. It wasn't the same collider as in the editor, so it also resulted in a null reference error. I'm not sure if that's the case for you, but could be worth looking into. I found out by using Debug.LogError and enabling debugging in the development build.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Unity build error android 0 Answers
PropertyHandler.cs 203 error not accessing materials of a model 4 Answers
Data folder not found 6 Answers
Build to WEBGL: Development build will not finish sucessfully 0 Answers