Script not working in build - ok in editor

This topic keeps coming up and after scouring the forums/answers I could never find a solution that works. So here is my steps that fixed my problem - and other general fixes for common problems.

  1. In build settings make sure all your scenes are present (my need to click add current).

  2. Make sure you game has zero errors, play through all the options, going through every script.

  3. Restart your computer.

  4. Check the log of the build, (for windows) its in the [buildname]_Data folder where you build the game. The file is called output_log.txt and should be empty except for general details like you gpu, settings etc.

  5. Reimport All. This is under “Assets” at the top in Unity.

  6. Delete all “old” builds of the game, including any old folders of the actual game (say you copied it to another directory… make sure you delete the old one).

  7. Try moving to a different system, get a friend to try and build it.

If none of the above work, make backups and try this step.

  1. Build your game, in the [name]_Data folder look at the file called Assembly-UnityScript.dll and take a peek at the “Date Modified”. The date should be that day - if it is showing an older date Unity is finding an older copy of the scripts and using that instead. Search your computer for “UnityScript.dll” and there only should be one with today’s date. (Ignoring the UnityScript.dll.mdb - that’s something else). In my case I had a copy of the UnityScript.dll within a sub-folder that Unity was using for builds instead of re-compiling.

  2. If that still doesn’t work… well, the last thing to do is make a new project and import the assets (some had luck with making a package of the old game and importing that way). You will lose most the pre-fab setups and you will have to re-create the level.

Hope this helps - feel free to add to this so people can find “the one” thread with all the answers.

8 Likes

I had I case like that. But in my case the reason was the below script which was running ok in editor

In order to get it running in player I had to break it into two loops by moving

to the second loop
so that the content of stTransforms now remains unchanged thorough the first loop.

Thanks for this thread… Saved me from frustration!

One thing I would like to add to the list is to make sure that the game object with script attached is not tagged EditorOnly.

To get there, select game object from hierarchy → inspector → tag. If it is tagged EditorOnly, change it to Untagged.

For some reason my main script spawning object was tagged EditorOnly and everything only worked in the editor play and not in builds.

5 Likes

I’d like to add to this list, since I just had this problem from a different cause and finally solved it.

(Unity 4.2) In my Build Settings window, all of the correct scenes seemed to be listed under “Scenes In Build”. But something must have been screwed up in there under the hood. I removed all the scenes from that list (‘DEL’ key), and re-added them all one-by-one, and it worked fine!

Just one more thing to try!

2 Likes

Same issue with Unity 4.5.2: app in editor ok, build broken.
Player log warnings about an unsupported shader. (check your exe’s folder in windows once you build it and search for the player log)

FIX:
Check if in some of your shaders you have any property with a very low or very high number (ex: 0.000000001 or 100000000 for example) in the shader properties code.
If this is the case, Unity is changing it to scientific notation when compiling the shader and it will not work anymore!
To fix it, just change this property number to a number with less digits.
In my case, I had a shader property of type Range with the lower value being 0.00000001
I just removed the Range property and put a float property instead with a 0.001 value and then put a 0.00000001 in the Unity editor.
Now it works…
(more than 3 hours of exploding my head against the wall)

@anon_7446384
What do you mean by scripts not working in builds? Does the build not even start up? Is it misbehaving? (if so, how?) Is the editor not successfully completing a build?

I filled a bug report yesterday about this.
I uploaded the project too

http://fogbugz.unity3d.com/default.asp?621502_2hgd6nnbps70e6ma

Ok cool. Thanks for the report. QA will pick up from here.

BTW we never redistribute or similarly utilize repro projects we get through QA. Way may incorporate them or parts of them into our testing (to check for regressions, for example), but rest assured that your data never goes anywhere.

Solution 4. worked for me. It reported that tag was missing although it was there. I just recreated the same tag and it worked :slight_smile: Thanx for this list man! :slight_smile:

I passed a long time trying to solve same problem (run OK on editor and KO on build). I solve it looking at player.log file (see player.log location at Unity - Manual: Log files) and for the problem was a resource loading. What I learned is that this kind of problem (run OK on editor and KO on build) can be a lot of differents things. Solving the problem in the log file is the very first step to do.

The pitty is that when a scene script does not ran in a build binary it’s because of a runtime error on that script only visibile in player.log with no way to see it, even in a development build.

Tip : test & solve first in standalone build on your desktop, then try on other platforms, it’s easier to see player.log content.

1 Like

wen i try to use the restarter, i’m getting this error, and dont understand:
Invalid editor window UnityEditor.SceneHierarchyWindow
UnityEditor.EditorApplicationLayout:FinalizePlaymodeLayout()
in the play mode, it doesnt work. any help would be much appreciated! will upload project if needed

I had an irritating problem that it worked in build but not with runtime. So the problem turned out to be:

I imported the backup project to an new empty project and when playing in editor everything worked. But in build collision just didnt worked. Using Development Build in win I got an error warning “missing tag” so the prefab from resources made a tag in editor-gameplay but in build the tag was not created. So i made the “missing tag” in project and everything worked!

Thanks for tips in this thread for using development build for debugging. :smiley:

The problem for me is my coding, Check your coding structures its need to be efficient and clean. also keep your code shorter as possible.

wow thanks, I had a similar problem too and couldn’t work it out for ages. was in Unity 5.6 and 5.5. In Editor mode the objects are tagged correctly but in live build they are not and I can’t tell because there’s no interface.

I’m not sure yet if mine were EditorOnly but I’d suggest a Debug default which alerts Devs when there is EditorOnly tagged objects in a final build.

1 Like

I had this problem, and it was after I deleted a Tag from the list under the inspector. Once you delete a tag, there’s a little message that says it will be removed when you re-open the Unity Editor, and when I tried to build before restarting the Editor, some of the tags were not working, but they still worked in the editor.

Try restarting your Editor, and checking tags on the associated problematic GameObjects.

I think I had the same problem as some others here, and especially losingisfun. However, restarting the editor did nothing. The message just stayed the same. So for anyone else having the same problem:

Open “ProjectSettings / TagManager.asset” with a text editor. There will be a list of tags, like so:

tags:

  • Wall
  • Rail
  • Blast
  • Sphere

If your list includes empty lines (like the first one in my example), delete them to fix all your problems. Apparently all Unity builds prior to 5.5 were able to deal with these nameless tags, which is why I had to go through years of my file history to find out how this problem started :slight_smile:

I have a with tags that don’t get exported,
I use Javascript,
The Script Says: var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
But The Tag Camera.main doesn’t get exported

I also had a problem when testing my multiplayer turn based game. When running a version in the editor and one in the build, everything was fine. But when running two build, there occurred some problems.

After a long debug process it turned out that there was something wrong with my understanding of the Unity PlayerPrefs I used in my code to set some booleans in a particular state.

I was storing the last opened scene name in a preference and in the next scene I read the preference. If there was a previous scene a bool must be set to true. If there wasn’t the bool must be false. What I did was immediately resetting the preference with an empty string after I read it. Apparently, this caused problems when testing two networked builds on the same machine I guess. Because, when the second instance of the game read the preference at the start, it was already empty due to the actions of the first instance. I fixed it by setting the preference to an empty string in the onDisable call of my script. Since the game only uses it at the start.

Hopefully this can help someone avoiding a night of debugging

right now i am struggling with my reflection probes (Showroom, VR)
everything works fine in unity, as soon as i build my exe reflection probes don’t get updated anymore.
not working via refresh by script, nor when i set them to realtime every Frame…

any idea ? i am working through all pointers in this thread right now

iam getting this error in the Output_log

(Filename: C:/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
TagName 5