Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Script not working in build - ok in editor

Discussion in 'Editor & General Support' started by dvisions, Feb 8, 2010.

Thread Status:
Not open for further replies.
  1. dvisions

    dvisions

    Joined:
    Feb 8, 2010
    Posts:
    1
    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.

    8. 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.

    9. 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.
     
  2. tomekkie

    tomekkie

    Joined:
    Jan 23, 2011
    Posts:
    120
    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.
     
    Last edited: Feb 3, 2011
  3. gormee

    gormee

    Joined:
    Mar 20, 2012
    Posts:
    14
    Thanks for this thread.. Saved me from frustration!
     
  4. XiaoHong

    XiaoHong

    Joined:
    Jun 2, 2013
    Posts:
    2
    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. rockyourteeth

    rockyourteeth

    Joined:
    Jul 25, 2013
    Posts:
    17
    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!
     
    arkidsindo and shough like this.
  6. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    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)
     
  7. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    @dvisions
    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?
     
  8. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
  9. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    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.
     
  10. KwahuNashoba

    KwahuNashoba

    Joined:
    Mar 30, 2015
    Posts:
    110
    Solution 4. worked for me. It reported that tag was missing although it was there. I just recreated the same tag and it worked :) Thanx for this list man! :)
     
  11. NeneChico

    NeneChico

    Joined:
    Oct 4, 2014
    Posts:
    14
    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 http://docs.unity3d.com/Manual/LogFiles.html) 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.
     
    shieldgenerator7 likes this.
  12. calcanius

    calcanius

    Joined:
    Jan 30, 2016
    Posts:
    1
    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
     
  13. peterkungen

    peterkungen

    Joined:
    Feb 5, 2015
    Posts:
    18
    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. :-D
     
  14. Vane486

    Vane486

    Joined:
    Feb 25, 2017
    Posts:
    1
    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.
     
  15. originalterrox

    originalterrox

    Joined:
    Feb 6, 2015
    Posts:
    40
    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.
     
    shieldgenerator7 likes this.
  16. losingisfun

    losingisfun

    Joined:
    May 26, 2016
    Posts:
    35
    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.
     
  17. Multiplayer

    Multiplayer

    Joined:
    Dec 29, 2012
    Posts:
    15
    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 :)
     
  18. Blue-Studios

    Blue-Studios

    Joined:
    Jul 3, 2017
    Posts:
    1
    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
     
  19. Bertlapp

    Bertlapp

    Joined:
    Sep 7, 2015
    Posts:
    44
    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
     
  20. SnowInChina

    SnowInChina

    Joined:
    Oct 9, 2012
    Posts:
    204
    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
     
    Last edited: Feb 26, 2018
  21. jdlaay5

    jdlaay5

    Joined:
    Apr 10, 2018
    Posts:
    1
    Maybe its me or not; I am new to using Unity but I completed the UFO tutorial this weekend and as of this week is no longer available, with a little research I came upon this note in the build documentation, "Any GameObject in a scene that is tagged with ‘EditorOnly’ will not be included in the published build. This is useful for debugging scripts that don’t need to be included in the final game." So I went into the editor and created a tag reference to each game object and fixed the issue for my problem. i.e player TAG: player, pickup TAG: pickup; canvas TAG: canvas.

    Hope this helps for anyone with the same problem. Haven't really looked into the tag attribute very much but again seemed to fix mine.

    Have a great Evening!
     
  22. AVFA

    AVFA

    Joined:
    Jul 28, 2018
    Posts:
    1
    hi, i had this problem in 2018.1 version. I write
    "#if UNITY_STANDALONE || UNITY_WEBPLAYER || UNITY_EDITOR" this kod in a script under Update method. and finished with "#endif". This lines caused problems. I use this codes many of my scripts but only caused in one script. because of this I can not build for Android. I can build and run after deactive with "//" symbols. Interesting bug.
     
  23. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    851
    The Post Processing Stack v2 was in my project, and not throwing and error during play, but when my build failed the only error displayed was a Player script not compiling error (very vague). In the console upper right corner, left click the symbol and select Stack Trace Logging - Error - Full. After I did that the PPS v2 Error began to show. I deleted the PPS v2 from my project folder, and the build works now. Good Luck to all.
     
  24. drafj

    drafj

    Joined:
    Dec 12, 2019
    Posts:
    3
    my solution was so weird, I removed the script and added it again, and the error magically appeared in the console, and then I commented the line that has the error (the line is completely fine) and ran it, and it works again in the editor , then I build and finally works,

    afterwards, I uncommented the line and everything works magically, I'm still confused :( but happy because xD works
     
  25. shanzebali

    shanzebali

    Joined:
    Aug 18, 2015
    Posts:
    4
    Hello i am trying to build a Maps application using unity engine every thing runs fine in editor. The project builds successfully i can even run it on the device. Logcat shows no errors. Even i can check the debug.logs while i perform an action. I've checked most of the scripts are running fine. However the maps layers that appears in the editor doesn't appear in the build. I can't figure out why is this happening. Any clues?
     
  26. LukasSacher

    LukasSacher

    Joined:
    May 2, 2019
    Posts:
    14
    Another point to mention is that you should take a look at the execution orders. Most often they are different in a build than in the editor. This can mess up a lot of things. Just use a tag in front of a class or look at a tab called "script execution order" in the project settings.

    Edit: The tag is [DefaultExecutionOrder(value)]
     
    Last edited: Dec 31, 2020
  27. shieldgenerator7

    shieldgenerator7

    Joined:
    Dec 20, 2015
    Posts:
    39
    For some reason, my log file was in the AppData folder and not in the build folder. If you can't find your log in the build folder, try this folder instead:

    C:\Users\[your_user_name]\AppData\LocalLow\[your_company_name]\[your_game_name]\Player.log

    If you can't find the AppData folder, make sure you turn on viewing Hidden Items
    (View->Hidden Items (Alt+V, H, H)).
     
  28. suleymanbucuk

    suleymanbucuk

    Joined:
    Mar 13, 2019
    Posts:
    11
    I got this issue, my game works on editor but not other builds. So i have built my game for windows in development mode with unity's self debugger to see what's going on.I ran the game. All i saw is lots of missing scripts in debug mode. I had used a third party program to recude polygons of 3D objects, named Poly Few, but it didn't fit my project. So i removed that 3th party tool from the project. Before, that asset added a script to all 3D objects in the project, after removed it, missing script issue appeared whole those objects. So i cleaned missing scripts and then game works again in all platforms.

    As @peterkungen pointed, the best way to start is building your project in debug mode and see what's going on.
     
  29. SuperCrow2

    SuperCrow2

    Joined:
    Mar 8, 2018
    Posts:
    584
    For me its the the high score not working on level 2, and you cant get to level 3. It all works fine in editor mode.
     
  30. Deeje

    Deeje

    Joined:
    Feb 1, 2014
    Posts:
    4
    Not sure if this will help anyone, but here's how I fixed mine. I had a property called Button that returned a private UI button called _button. Not sure if it's because of the name or what, but when I deleted the property and just made the _button public, the issue went away. After like 3 hours of riding the struggle bus.
     
  31. MichelleMerry

    MichelleMerry

    Joined:
    May 7, 2019
    Posts:
    1


    I have a Uni project that needs to be handed in soon and my enemies would not attack the player in the build. I changed the Unity default tag to my own and now it works. I don't normally post but I wanted to tell you how your my hero, thank you for commenting on here. :)
     
  32. WyattHawk

    WyattHawk

    Joined:
    Feb 2, 2021
    Posts:
    3
    None of these worked, Im dieing inside, their are four hours left in this Game Jam and I just tested one last build and it broke.... I am going to die if this doesn't work......
     
  33. Kristapsmadeapp

    Kristapsmadeapp

    Joined:
    Jul 10, 2019
    Posts:
    9
    I had issues with script working on build if I used

    GameObject.FindGameObjectWithTag()

    instead of that I changed it to

    GameObject.Find()
     
  34. Melanzue

    Melanzue

    Joined:
    May 12, 2020
    Posts:
    8
    Are you ok, man?
     
    atomicjoe likes this.
  35. aggaton

    aggaton

    Joined:
    Jul 3, 2021
    Posts:
    113
    Thanks for this, it should be mentioned if you haven't set the company name to anything, it will be under "DefaultCompany".
     
  36. aggaton

    aggaton

    Joined:
    Jul 3, 2021
    Posts:
    113
    For me, adding log messages that go to the Player.log and attaching the debugger to walk through the code around that unexpected message, was the key for solving one of my issues. Turns out I was calling a method in an object before it's Awake() had been called to initialize stuff. So it is important to check order of execution. I guess I had a vague rosy misconception, that all Awake() methods are called in all objects before anything else when a scene loads. Which is obviously not true. Another issue was due to execution order of the user input script. I had to put that last after everything else, otherwise other code affecting movement would be starved.
     
    Last edited: Aug 26, 2021
  37. anishkelkar

    anishkelkar

    Joined:
    May 24, 2021
    Posts:
    1
    For me, it started working after you committed .cs.meta files. Rider's UI can be tricky, and one may miss committing the same.
     
  38. cgrtml

    cgrtml

    Joined:
    Dec 5, 2021
    Posts:
    1
    Get a development build and solve all the errors and warning then it should be fine.
     
  39. ASDF_alpha

    ASDF_alpha

    Joined:
    Aug 25, 2020
    Posts:
    29
    That didn't' work for me
     
  40. ASDF_alpha

    ASDF_alpha

    Joined:
    Aug 25, 2020
    Posts:
    29
    I have no errors but one of the scripts doesn't work,they other one works normally and only just one doesn't work,I really have no errors and warnings so......
     
  41. ASDF_alpha

    ASDF_alpha

    Joined:
    Aug 25, 2020
    Posts:
    29
  42. MrTawahi

    MrTawahi

    Joined:
    Aug 13, 2021
    Posts:
    1
    Tried 15+ solutions its 5 days of smashing my head on desk so I come to this page and read some comments and I tried readding all scenes and removed my tag and readd the removed tag and that works fine Oh my God I am going to close the project but efforts are enough to solve all problems
     
  43. sadpanders

    sadpanders

    Joined:
    Jan 22, 2023
    Posts:
    12
    My problem was i stupidly changed scene name and forgot, was building with old scene. im a dork :D just learning
    made it seem like half my scripts were not working and half the objects were not there either
     
  44. ByatisGlaaki

    ByatisGlaaki

    Joined:
    May 11, 2023
    Posts:
    1
    I hope you live your best and happiest life on this earth and may god bless you in everything. Thank you so much. You have no idea how grateful I am. Trying to fix this for hours and it's been such a small thing that I couldn't see.
     
Thread Status:
Not open for further replies.