Game works great in the editor, doesn't work in player.

I’ve done some research about this before asking here in hopes that I could solve it on my own but after a few hours of tweaking, testing and the same results I hope that others may have some solid suggestions.

I’m working on a 2D tower defense type game and I have some custom path work - for multiple paths - that I’ve done for objects to “walk” through the level from the start to their goal. In the editor, this all works splendidly. When I go to do any builds (PC or Web), much of my level works but nothing that is associated with the path (enemies, etc.) work. It is hard to have a tower defense game when nothing will take the paths. :slight_smile:

I’m not sure that posting all of my code here would help as it would be a lot to post the pathing system so I’ll post the overall structure and error in case others can help.

Basic structure:

  • Path gameObjects in my hierarchy contain sub gameObjects that hold the “waypoints” for that path.
  • My path engine (which takes a gameObject given and moves it along the waypoints as time passes) takes the Path gameObject as a reference in the editor.

In the Unity editor, all goes well and the path engine recognizes the Path gameObject and the contained waypoints. In the Unity player, the path engine receives a null for the same assigned Path gameObject. I have a null check in the Path gameObject in the Start() method so I know that it begins as null and I’m not botching the value in Update(), etc. I don’t understand how/why this is happening. Visual inspection tells me that it is clearly assigned properly in the editor.

I’ve tried rearranging items in the hierarchy, providing them at various levels. I’ve worked to move the waypoints from the editorOnly tag. I’ve installed my codebase on another system and tried to build it. Still, nothing.

Any thoughts? Thanks for reading through.

Edit: I’m using Unity 4.5.5p3.

For future visitors, here are some things you should check:

  1. Ensure you’re not loading anything from disk with absolute paths or relative paths that can change. Use the built-in Resource loading that Unity offers to have all of that handled automatically.

  2. Ensure you don’t have any compiler conditionals like #if UNITY_EDITOR that may be unintentionally causing parts of your code to not be compiled to the final build.

  3. Make sure none of the objects you want to show up in your release build are tagged with editorOnly. This will cause those objects to not be compiled into a release build.