Unity fouls up build

I’ve got a problem with Unity; and I’m kind of fed up with troubleshooting it with no success.

Basically, I’ve got a third person shooter I’m working on. When I run my project inside the editor, everything works as expected, except when I die and respawn, my sighting system is broken. After a bit of troubleshooting, I find that it’s a problem with the prefab. I don’t know what the problem was, but dumping the old prefab and creating a new one fixes the bug. So I’m happy, and make a build of my game.

Remember, in the editor, everything works well.

In the build I just made, the sighting is broken as soon as you start the game.

I’ve restarted Unity, rebuilt, re-did prefabs, and even exported assets as a package into a new project. Upon migration to a new project, sighting was broken again, but replacing the prefab worked.

The build still doesn’t. ANY help is appreciated.

Most inconsistencies I’ve seen between builds and editor are a result of the order in which Awake and Start are called on objects.

If you’ve made a mistake in expecting a certain object or variable to be in a certain state in another objects Awake or Start method, it might not be apparent in the editor, because the order the objects have those methods called is always the same. However, the build might not allocate the objects in the same order at all. Therefore those inconsistencies could show up that probably should have shown up in the editor but didn’t as a result of the object allocation / calling order always being the same.

Carefully examine your Start and Awake methods to ensure that no assumptions are being made about the order they are called in. If you need that order, consider either a special class that calls Initialization methods of classes in a specific order, or moving code between Awake and Start emthods as appropriate (Awake is called for all objects before Start is called for all objects).

I don’t use Start(), I use Awake() and sometimes type outside of functions.

EDIT: Would just changing all my stuff from Awake() to Start() and putting all code that is currently outside a function into the Start() function fix this? The scripting reference just says that code outside a function is run when the script is loaded.

Anyway, I’ll research this a bit and post back here with my results.