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 changes don't compile

Discussion in 'Editor & General Support' started by justforunity, Aug 2, 2017.

  1. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,688
    So as I understand @lukaszunity , the complaint is that while the loading process works as you explained, Unity first, asmdef second and then everything else.

    The problem is that the first error in any asmdef, block any other asmdef being compiled and loaded.

    So any one asmdef failure results in no asmdef's being loaded which makes it a lot harder to diagnose and resolve compile issue. And if there are multiple errors in each asmdefs, this is creating terrible reload times due to having to keep reloading fixing one issue at a time.

    Ideally, one failure shouldn't stop the compilation of all asmdefs, compilation should continue and load all Successful built components.

    So the build should:

    • Load the Unity engine / editor dlls'
    • Compile all asmdef's, regardless of failure. Load successfully built asmdef's, don't load ONLY those that fail.
    • Compile user code, regardless of previous failures. report new issues if there are dependancies.
    Aim is to avoid lengthy rebuild / reload times between fixing defects. A dev should be able to asses and fix all issues in a single build (preferably) instead of constantly having to rebuild for each fix.
     
  2. lukaszunity

    lukaszunity

    Administrator

    Joined:
    Jun 11, 2014
    Posts:
    461
    I think adding a option to not stop compiling on the first error in the editor would be a nice feature, so you can resolve multiple issues in one pass, as you mention.

    Changing the reload behaviour to support scenarios where there are compile errors, is a much more invasive change that has implications that could break partly break the project until the compile errors are fixed, as I mentioned earlier in this thread.
     
  3. StephenHodgson-Valorem

    StephenHodgson-Valorem

    Joined:
    Mar 8, 2017
    Posts:
    148
    @lukaszunity That's not what I was asking. Please take a moment to listen to what we're trying to propose.

    Could you break down exactly how the editor handles reloading assemblies right now (not on startup)?

    As far as I understand it (please correct me if I'm wrong):

    1. User edits a script.
    2. Editor unloads player assemblies.
    3. Editor compiles assemblies.
    4. If an error occurs then the Editor stops compiling and reloads old assemblies.
    5. if no error occurs then the Editor loads new assemblies

    Is this correct?
    Ideally we're asking to know if it's possible to have the following:

    1. User edit a script.
    2. Editor unloads player assemblies
    3. Editor compiles assemblies
    4. if an error occurs then the editor stops compiling
    5. Editor loads successfully built assemblies.

    I have a POC here for something similar to this using just the Assembly Builder that just kicks off a new build after the main editor loop is done. Thoughts?
     
  4. lukaszunity

    lukaszunity

    Administrator

    Joined:
    Jun 11, 2014
    Posts:
    461
    There is no distinction between player assemblies and editor assemblies in the editor. All assemblies are equal and all loaded into the same .NET Application domain.

    Reload works like this.

    1) Recompile scripts
    2) If there are 0 compile errors goto 3)
    3) Unload the .NET Application Domain and all assemblies (player and editor) in it.
    4) Create a new .NET Application Domain and load the new version of all assemblies (player and editor) into it.
     
  5. StephenHodgson-Valorem

    StephenHodgson-Valorem

    Joined:
    Mar 8, 2017
    Posts:
    148
    That makes a lot more sense now, thanks.
     
  6. StephenHodgson-Valorem

    StephenHodgson-Valorem

    Joined:
    Mar 8, 2017
    Posts:
    148
    Is there a way that we can at least create a new domain with the successfully built assemblies and leave the broken ones out?
     
  7. lukaszunity

    lukaszunity

    Administrator

    Joined:
    Jun 11, 2014
    Posts:
    461
    That would be possible and so would trying to old the old assemblies. Both scenarios could create issues that can could then only be resolved by fixing the compile errors and reloading all assemblies. E.g. the model we have today.

    The point I'm trying to get across is that even if there are some issues with the current model of how assemblies are reloaded, the alternatives also have their own share of issues.
     
  8. StephenHodgson-Valorem

    StephenHodgson-Valorem

    Joined:
    Mar 8, 2017
    Posts:
    148
    Thanks for taking the time to break this down for us.

    I'd def open to the idea of making this optional and seeing where it goes.

    In the meantime, having something that detects if the error is from using a missing language feature and having the editor prompt you to switch and reload the editor using the 4.x instead of the 3.5 scripting runtime would pretty much make this a non issue for me.
     
  9. StephenHodgson-Valorem

    StephenHodgson-Valorem

    Joined:
    Mar 8, 2017
    Posts:
    148
    @lukaszunity does it makes since to not stop on the first compile if importing an asset package and there were previously no compile errors?

    For example:

    1. No compile errors in project.
    2. User imports an asset package
    3. Editor does not stop on first error, like when starting the editor for the first time.
     
  10. JamesNBishop

    JamesNBishop

    Joined:
    Feb 2, 2017
    Posts:
    1
    just updated to 2018.1.7f1 using win 7 64.....same issue
     
  11. Samiix3D

    Samiix3D

    Joined:
    Aug 4, 2018
    Posts:
    1
    Hi I had the same problem of refresh in the compilation of my scripts but I solved this problem here is the solution:

    So I use the version 2018.1.9.f1 of "UNITY ENGINE" and it is a solution to my specific problem so if for you it helped you so much better if the problem is elsewhere I think.

    I'm also on VisualStudio 2017, it's gone.

    PS: I'm French sorry for the mistakes of hortograph :)

    Then go to "Edit" then:
    Go to "Preferences" then
    Go to "General" then
    Click on "Auto resfresh" Voila

    So I solve my problem like this by hoping to have helped someone :)
     
  12. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    150
    I ran into this issue with Unity 2018.2.1f1.
    All of the sudden changes I made in my scripts didn't compile in Unity.

    I haven't read the whole thread, but I did find a fix for my case.

    For me it was due to a compile error that did not get logged to the console about Unity's Networking MessageBase serialization. I was had a List<Vector3> public member in a class derived from MessageBase. After restarting Unity I noticed this message in the console (it wasn't there before the whole time). Removed that code and everything was working again. Maybe this is helpful for some of you?
     
  13. oguzhan-uglu

    oguzhan-uglu

    Joined:
    May 4, 2014
    Posts:
    11
    hi, i have had this issue too. auto refresh was disable and I reenabled it. 2018.2.2f1
     
  14. fatinrakib

    fatinrakib

    Joined:
    Dec 14, 2018
    Posts:
    1
    why i have this error whe importing leap module asset
    Copying assembly from 'Temp/Assembly-CSharp.dll' to 'Library/ScriptAssemblies/Assembly-CSharp.dll' failed
     
  15. brkic123antonio

    brkic123antonio

    Joined:
    Jan 11, 2019
    Posts:
    1
    Guys I made a little project and then I got an update notification. i updated to 2018.3.1f1 and VS kinda changed. I tried to write some code and it just won't compile.
     
  16. DinosCharmGames

    DinosCharmGames

    Joined:
    May 9, 2018
    Posts:
    25
    We are getting this issue on 2019.1.14f1. Checking the error log after modifying a script shows the editor picks up the script change, writing the line "Updating Foo.cs". After this entry though it does not kick off a compilation phase. We have checked that auto refresh is enabled. Only one user is experiencing this. Any thoughts?
     
  17. apostro

    apostro

    Joined:
    Dec 5, 2012
    Posts:
    12
    Still have this issue in 2019.2.7f2. Scripts changed in Visual Studio will not transfer to Unity. Restarting VS deletes your edited script and loads old one.
     
  18. Paalo

    Paalo

    Joined:
    Jan 20, 2016
    Posts:
    8
    Had this problem in Unity 2019.3.0b7.
    Went to Edit > Preferences > General, and set "Auto Refresh" to TRUE.

    Apparently the setting had been disabled automatically for me too for some reason. But that fix seems to work for me, let's hope the application doesn't decide to change it back behind my back again!

    Thanks for the tip @lukaszunity =)
     
    szymongsetapp, Pwarier and irenya like this.
  19. nantoaqui

    nantoaqui

    Joined:
    Oct 1, 2014
    Posts:
    42
    I'm facing the same issue. Here's my workflow:

    1- Edit some script on VS CODE
    2- Click on Unity in order to get the code compiled.

    The script doesn't get compiled until i move to step 2, which is quite annoying :(
     
  20. whitexroft

    whitexroft

    Joined:
    Oct 22, 2012
    Posts:
    48
    I am experiencing this issue on 2019.3. Didn't have it on 2019.2
    Out of 3 machines working on the project right now 2 are affected.
    Cannot reproduce it in a new project

    Autorefreh is on
    It recompiles succesfully with no errors
    Ive deleted the entire Library folder and reimported
    Tried both asset pipeline versions

    The only way to sucessfully recompile for me is restarting the editor

    edit 1: apperently it has something to do with my own library that is being placed in Plugins folder. It existance doesnt let assembly definition to reload.
    edit 2: got able to make a repro project and report it. Case 1226326

    Begin MonoManager ReloadAssembly
    Symbol file LoadedFromMemory doesn't match image D:\Projects\Airhead\Library\PackageCache\com.unity.ext.nunit@1.0.0\net35\unity-custom\nunit.framework.dll
    Native extension for WindowsStandalone target not found
    Refreshing native plugins compatible for Editor in 0.83 ms, found 2 plugins.
    Preloading 0 native plugins for Editor in 0.00 ms.
    Building style catalogs (6)
    StyleSheets/Extensions/base/common.uss
    StyleSheets/Northstar/common.uss
    StyleSheets/Extensions/fonts/inter.uss
    StyleSheets/Extensions/base/dark.uss
    Packages/com.unity.timeline/Editor/StyleSheets/Extensions/common.uss
    Packages/com.unity.timeline/Editor/StyleSheets/Extensions/dark.uss
    [MODES] Loading mode Default (0) for mode-current-id-Airhead
    Mono: successfully reloaded assembly
    Refresh completed in 0.000002 seconds.
    - Completed reload, in 1.917 seconds
    Platform modules already initialized, skipping
    Refreshing native plugins compatible for Editor in 0.82 ms, found 2 plugins.
    Preloading 0 native plugins for Editor in 0.00 ms.
    Refresh completed in 6.215581 seconds.
    RefreshInfo: RefreshV2(ForceSynchronousImport)
     
    Last edited: Mar 9, 2020
  21. Jimelo

    Jimelo

    Joined:
    Mar 23, 2020
    Posts:
    1
    So how do you fix this completely? I am trying my best to find something online to this fix and I am dealing with the same problems as whitexroft
     
  22. travlake

    travlake

    Joined:
    Oct 4, 2019
    Posts:
    50
    My changes - made in Inspector or in scripts - are also not always being reflected in builds. Play mode in editor works fine.

    Unity 2019.3.7f1
    Windows 10
    Building targeting WebGL
     
    Breno_Rangel likes this.
  23. achotai2

    achotai2

    Joined:
    Mar 30, 2020
    Posts:
    1
    I'm getting this same problem as well, using Unity 2018.4.21f1 and VS..... The weird thing is that I can make two changes to different functions in the same class, one of those changes will show up in the compile immediately, the other won't show up until I reload Unity.
     
  24. X28

    X28

    Joined:
    Jul 15, 2015
    Posts:
    8
    I have the same issue with Unity 2019.4. it happens rarely.
    but I think, it's the Visual Studio fail. VS shows that all changes are saved on the file, but when I open the .cs file in the Notepad, there are no changes :| (unity was right)

    I change my codes in the Notepad and save them, it works correctly.

    Unity 2019.4.15f1
    Windows 10
    Visual Studio 2019
     
    Last edited: Jan 11, 2021
  25. davidwhiffen

    davidwhiffen

    Joined:
    Sep 26, 2019
    Posts:
    14
    This worked for me just now!
     
    DSivtsov likes this.
  26. ohthepain

    ohthepain

    Joined:
    May 31, 2017
    Posts:
    100
    I am frequently finding that some of my files that I have edited in VS Community have not compiled when I run or debug. It's not consistent.

    To get my changes to work I frequently have to
    - go back to the editor
    - add a compilation error
    - go to unity
    - wait for it to compile and report the error
    - go back to editor and fix the error
    - go back to unity

    Then it compiles and works. But man, what a pain.

    Deleting "Library/ScriptAssemblies" didn't work for me. Many many runtime errors after that.

    I wish it would just compile and run when I hit the run button!
     
  27. xSneepy

    xSneepy

    Joined:
    Jun 2, 2016
    Posts:
    2
    I still have the same problem in Unity 2020.3.8f1.
    I'm using Visual studio community version.
    Everything is checked in Visual studio and Unity.

    Hope to get some help cause it's frustrating to switch windows for every little change.
     
  28. KnightWhoSaysNi

    KnightWhoSaysNi

    Joined:
    Jan 21, 2017
    Posts:
    13
    Issue still present in Unity 2021 .....
     
  29. kloogens

    kloogens

    Joined:
    Jul 1, 2015
    Posts:
    109
    I've been fighting this issue for 4 hours now.

    It says it can't find a component I just made. The class and file name match, I've sprung that trap many times before.

    Visual Studio compiles just fine while unity will not update those changes no matter what I do.
    I've rebuilt, restarted both Unity,VS, and even my entire machine.

    This is infuriating, once again I can't make any progress because I'm fighting with the tools I pay for.

    Edit: I changed the name of the .cs file in visual studio to godfuckingdamnit.cs and it worked.

    Then I changed it back to something more appropriate and it is still working.
    However, attaching Unity to the VS debugger caused it to happen again, and only restarting the editor fixed that condition.
     
    Last edited: Aug 16, 2021
  30. kloogens

    kloogens

    Joined:
    Jul 1, 2015
    Posts:
    109
    Try renaming the file and classname in Vs. After 4 hours, that is how I got it working again.
     
  31. endasil_unity

    endasil_unity

    Joined:
    Jun 28, 2018
    Posts:
    19
    This is still an issue with Unity 2020.3.21f it gives errors on rows that no longer exist and if I try to add an error by adding "ööööö" to a different row the errors does not change.
     
  32. kauheaa

    kauheaa

    Joined:
    Sep 7, 2018
    Posts:
    1
    Same problem with 2020.3.23f1, changes in script are saved and show up updated in the inspector when the script is inspected, but the game uses the old version of the script.
     
    Thunderik likes this.
  33. Rachini

    Rachini

    Joined:
    Jan 7, 2019
    Posts:
    2
    Hello,
    i have unity 2021.1.10f1, and i have the "Run in Background" option enabled in the edit/project settings/player/resolution and presentation
    and i have vs2022 17.06 and i have the tools/options/tools for unity/general/explorer/automatic project reloading set to true.

    but i still have to save the modified script in vs2022 AND THEN put the unity editor in focus so it recompiles the scripts....

    i still havent found a solution to make the unity editor recompile the scripts in the background.
    any new ideas guys ?
     
  34. Thunderik

    Thunderik

    Joined:
    Apr 28, 2020
    Posts:
    32
    Experiencing this in 2020.3.25
     
  35. Rachini

    Rachini

    Joined:
    Jan 7, 2019
    Posts:
    2
    Apparently the Unity 2020.3.28f1 LTS does not have this problem.
    i switched from 2021.1.10f1 to 2020.3.28f1 LTS and everything is working fine.
     
  36. lsegal

    lsegal

    Joined:
    Oct 17, 2015
    Posts:
    5
    Seeing this with VS Code and 2022.1.0b16. You figure this would have been fixed by now?
     
  37. winterscha

    winterscha

    Joined:
    Oct 29, 2021
    Posts:
    1
    Visual Studio (2022) 17.2.3 and 2020.3.14f1.
    Why isn't there a button that can rescan for changes or simply a compile option in the menu? I mean this isn't a new problem!
     
  38. dylanspin

    dylanspin

    Joined:
    Jul 25, 2019
    Posts:
    2
    What fixed the issue for me was removing the visual scripting package from the project.
     
  39. victornor

    victornor

    Joined:
    Jan 17, 2014
    Posts:
    87
    6 years later, this issue still persists in latest LTS editors.
    What the F*** are you doing? Unity has so many random issues always.
    Get your quality control in order and build a functional product....
     
    KUBO-Fredrik likes this.
  40. KUBO-Fredrik

    KUBO-Fredrik

    Joined:
    Jan 5, 2022
    Posts:
    2
    Same sh** still happens!! ...LTS 2022.3.2f1
    Seriously? (╯°□°)╯︵ ┻━┻
     
    FrozenN likes this.
  41. GhettoWizard

    GhettoWizard

    Joined:
    Dec 13, 2020
    Posts:
    3
    Glad this only still happens to me in 2022 releases, while there's 4 pages of discussion here with zero fixes to be found. Love that! Great work Unity!