Search Unity

Game works in EDITOR but not in build?

Discussion in 'Editor & General Support' started by SeanGause, Jun 28, 2017.

  1. SeanGause

    SeanGause

    Joined:
    Dec 24, 2015
    Posts:
    127
    My game works as intended in the editor, but when I build and run, it seems like part of one of my scripts stops working. I use the same script to open doors and to control a machine that dispenses health, but In build the health machine does nothing. Why does my game work in the editor but not when I build and run?
     
    FamishedMammal and QQQ_QQQ like this.
  2. SeanGause

    SeanGause

    Joined:
    Dec 24, 2015
    Posts:
    127
    It is worth mentioning that I don't get anything in the console when I play the game in the editor besides my Debug logs that I set. No errors that I know of.
     
    FamishedMammal and QQQ_QQQ like this.
  3. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    You can look at your console for debug logs and errors and stuff from the build - if it's a PC build it's in the XXX_Data folder as output.log, other devices have it in other places.

    One common issue that causes different functionality between the editor and builds, are scripts that must be initialized in a specific order - the order each Awake function is run in can change between editor and build, same with the order Start is run and Update, unless you set the ScriptExecutionOrder.
     
  4. SeanGause

    SeanGause

    Joined:
    Dec 24, 2015
    Posts:
    127
    I have several scripts that control doors and machines. How am I supposed to know the order that they need to execute in? They should all be running at the same time, I think, but I could be wrong.
     
  5. SeanGause

    SeanGause

    Joined:
    Dec 24, 2015
    Posts:
    127
    Solved the issue, but Im not sure how.
    I looked in the list of tags I had created and noticed that one of them said "(removed)" but it stayed on the list. It said to restart the editor to make it go away, so I did. Ta-da, my game suddenly worked in build. I'm still not sure if that is what caused it, however.
     
  6. domraGames

    domraGames

    Joined:
    Oct 19, 2018
    Posts:
    2
    Yeah I also had this problem.. I was frustrating for hours hahah. It was simple, because I deleted a tag and it will delete when you restart Unity. So restarting Unity solved the problem
     
  7. Dreadator

    Dreadator

    Joined:
    Mar 17, 2017
    Posts:
    2
    Bro, you just saved me. Had the same issue with it working in the editor and not in build due to a bloody removed tag! Thanks bro I was beginning to go insane, I had tried everything apart from restarting unity lol.
     
    Rbrinks likes this.
  8. Nsingh13

    Nsingh13

    Joined:
    Dec 17, 2014
    Posts:
    38
    Fixed my problem for me too. Def. a bug on Unity's side.
     
  9. vladutstefan27

    vladutstefan27

    Joined:
    Sep 9, 2018
    Posts:
    5
    nothing on my end :-/
    hours and hours and still no solution
     
  10. Petchinsky

    Petchinsky

    Joined:
    Jul 26, 2019
    Posts:
    1
    Thanks for the solution. The same thing happened to me. Unity should automatically take care of deleted tags but doesn't.
     
  11. QQQ_QQQ

    QQQ_QQQ

    Joined:
    Jul 12, 2019
    Posts:
    15
    I have similar problem. My game works great in Unity but in Build some scripts does not work properly.
    My player (spaceship) shoots only few times and when other script start working (enemy spawner) my player can't shoot any more.
     
    SpaceWashed likes this.
  12. unity_TtSKlu4jQLkuGQ

    unity_TtSKlu4jQLkuGQ

    Joined:
    Nov 25, 2019
    Posts:
    2
    I have no tags and it stil doesnt work
     
    FamishedMammal likes this.
  13. h0neyfr0g

    h0neyfr0g

    Joined:
    Jul 13, 2019
    Posts:
    35
    I am also having this problem. My character moves with platforms in the editor, but lags behind in a build. What is happening?
     
  14. ahmedkhan-10

    ahmedkhan-10

    Joined:
    Mar 3, 2020
    Posts:
    1
    my game build is working but it is not showing my character and enemies but my player is colliding with enemies
     
  15. castrojoaquin91

    castrojoaquin91

    Joined:
    Mar 22, 2016
    Posts:
    3
    Hey if you're still struggling with this. Deleting the build folder and making a new one (instead of overwriting it) worked for me. :)
     
    Mosman and Joe-Censored like this.
  16. jencleary

    jencleary

    Joined:
    Oct 4, 2018
    Posts:
    4
    Thank you for this, I couldn't figure out why the game I'm working on wasn't detecting a saved game/load PlayerPrefs correctly in an executable (worked fine in the editor) and the ScriptExecutionOrder wasn't correct. Which I could tell from Debug statements in the output.log - so thanks for that too.
     
    mateeeiii11 likes this.
  17. savichpashaka88

    savichpashaka88

    Joined:
    Dec 6, 2019
    Posts:
    1
    Hi,
    Had this problem for hours and finally figured it out.
    It seems that Unity's default Tag references causing most of the issues.

    Try to:
    1. Replace references to default tags with your tags ("+Add Tag" at the end of the tag list).
    2. Don't use tag references if you can (FindObjectWithTag -> FindObjectOfType).

    Hope it will help someone =]
     

    Attached Files:

  18. Iceed_Out

    Iceed_Out

    Joined:
    Nov 29, 2021
    Posts:
    1
    Still dont worked for me only the Player Works but the Rest dont work i scripted my game with Bolt i tryed everything for days but nothing work for me
     
  19. Shrike3e

    Shrike3e

    Joined:
    Mar 12, 2022
    Posts:
    1
    For any one who tries all means in this thread but still does not solve the problem, check if you have code used for debug (method print() excluded), such as Debug.Assert()., which will be deleted in the build version.
     
  20. Noor23

    Noor23

    Joined:
    Feb 19, 2022
    Posts:
    28
    hey , i have similar problem i am using addressables to load a bunch of items on my scrollbar when i hit play it loads all items but when building into the device no items load ,,anyone knows how to fix this,, please help ,thanks
     
    sonali_unity285 likes this.
  21. KGBemployee

    KGBemployee

    Joined:
    Nov 15, 2015
    Posts:
    3
    I've also faced this exact issue.
    What I did was to remove the assembly definition and then recreate it. After that all of the references were correctly populated in the game build.

    Please note that I had not deleted any scripts or referenced items. It just "decided" that the references used in the build were not valid. Weird!...

    In any case, I hope that this helps someone out.
     
  22. Kaosknight

    Kaosknight

    Joined:
    Oct 30, 2020
    Posts:
    1
    I faced a similar issue when instantiating an object. The problem was that I had no way of referencing it and it was not in a resources folder so the prefab didn't exist in the build. Just put instantiated items in a resources folder.
     
  23. dogutyz

    dogutyz

    Joined:
    Nov 28, 2021
    Posts:
    1
    I would like to share my own experience in case there are people who still have this problem.

    I was using vibration in the game, but for some reason the vibration.Init() code did not work, so I was having problems when I got a build on the phone.
    I hope it helps someone.
     
  24. ArcherAV

    ArcherAV

    Joined:
    Jan 19, 2019
    Posts:
    1
    I want to share a story of my own failure.
    I've added some of the validation and setup methods to the OnValidate() but forgot that it is called only in Editor. So when the game was built, some characters didn't work as intended.
    Put crucial methods for runtime to Awake() or OnEnable() instead of OnValidate().
     
  25. unity_SZ7zgblrDXUcCA

    unity_SZ7zgblrDXUcCA

    Joined:
    May 1, 2021
    Posts:
    1
    If the Tag section of an object in Unity is "Editor Only", it will cause problems after build. Be careful about this.
    I repeated the codes for a day, but the problem was that the tag of an object was "Editor Only".
     
    rmele09 likes this.
  26. gamedevjake

    gamedevjake

    Joined:
    Aug 16, 2022
    Posts:
    27
    Want to share my story too! Took several hours to figure out.

    I use Unity NGO (Network for Gameobjects) and one of my NetworkBehavior scripts was checking if a sibling script component was not null, and if the script isActiveAndEnabled was true. I did this inside the Awake() method which worked fine in the Editor.

    Apparently some script objects were not "Active and Enabled" in the Build version of my game during Awake(). So I moved the check to the OnNetworkSpawn() function and that fixed my issues.