Certain gameobjects not in mobile build

I’m making a game in unity, targetting android. I have a few gameobjects, which are quads, which have some scripts on them, and the scripts use the dimensions and positions of the quad to procedurally add lots of other objects to make a long fence.

The fence is no longer appearing in the game when I run the built version on my android device, even though it appears fine when the game is run in the editor. After a bit of debugging using adb logcat, I realised that the fence-creating scripts were not running at all. I verified that the reason for that was that the quad objects are not present in the game world (by running a script which searched for one of the gameobjects and wrote the result to the log).

I am stuck now. I’m not sure how to investigate why these particular gameobjects are in the project, and are there when the game is played in the editor, but don’t make it to the mobile build. They were there when I was developing a few days ago.

edit: I just tested making a web player build, and that had the same problem.

Assets will be included in the build in one of two cases

  • You have a reference to them in the inspector
  • They are in the resources folder

Otherwise Unity will ‘optimise’ them out to reduce file size.

For clarification, how are you getting your reference to instantiate the GameObjects? This may give some clue as to which of these solutions is more relevant for your project.