Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Feature Request Ability to Disable Individual Script Compilation within Unity Editor

Discussion in 'Editor & General Support' started by JGameMaker92, Aug 8, 2023.

  1. JGameMaker92

    JGameMaker92

    Joined:
    Oct 15, 2014
    Posts:
    83
    Dear Unity Development Team,

    I am writing to request a feature that would significantly improve the workflow for many Unity developers, myself included.

    The Challenge:
    During development, it is common to have scripts that are experimental, outdated, or temporarily erroneous. Currently, there is no straightforward way to exclude an individual script from being compiled without resorting to renaming, moving, or other workarounds. These workarounds can lead to confusion, disrupt the organization of the project, or even risk data loss if not handled carefully.

    Proposed Feature:
    I propose adding an option within the Unity Editor to disable the compilation of specific .cs files. This would allow developers to "toggle off" individual scripts, preventing them from being compiled and excluding them from build errors, all without changing their location, name, or contents.

    Why This Matters:
    1. Flexibility: Developers can work on experimental features or temporarily broken code without affecting the rest of the project.
    2. Efficiency: By isolating errors to specific scripts, the build process becomes cleaner, and troubleshooting becomes more focused.
    3. Organizational Integrity: The current workarounds involve moving or renaming files, disrupting the logical structure of the project. A native toggle would preserve the project's organization.
    4. Accessibility: This feature would lower the barrier of entry for new developers, providing a safety net for experimentation and learning.
    Suggested Implementation:
    A context menu item (right-click) on a script in the Project window could offer an option to "Disable Compilation." This state could be visually indicated, perhaps with an overlay icon or different text color. Right-clicking again would offer an option to "Enable Compilation," returning the script to its normal state.

    Conclusion:
    While there are currently workarounds to achieve a similar outcome, they are often complex, risky, or disruptive. The addition of a simple toggle to disable compilation for individual scripts would be an elegant and powerful solution, enhancing the development experience for Unity users of all skill levels.

    I believe that many developers would find value in this feature, and I hope you will consider implementing it in a future release.

    Thank you for your time and consideration. Unity's continuous improvements and responsiveness to community needs are highly appreciated.

    Best regards,
    ~ChatGPT (She made me to do it, you should probably listen to her)
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    You already have that simple and straightforward option to disable entire scripts and it just takes two keystrokes in the script you want to disable entirely:
    • Ctrl+A
    • (whatever hotkey toggles single-line comments)
      • the multiline comment /* */ would fail to work if there are any existing multiline comments in the script therefore I'd opt to use the // style instead
    Alternatively, you can add your own scripting define symbol and enclose the script within it:
    Code (CSharp):
    1. #if ONLY_WHILE_TESTING_THIS
    2. // script here ...
    3. #endif
    Both are simple, straightforward solutions to the issue which every programmer naturally understands.

    The editor UI is the wrong place to implement such a feature as it would be totally unexpected having to look into the Inspector of a script to see if it is turned on/off.

    Coloring or adding icons to disabled scripts is not really an option IMO since there are several popular assets that change coloring and icons of the various editor views, which means such a visual indicator could be unreliable.


    Regarding the problem statement:
    • Outdated scripts: should be removed entirely - no reason to have them still in the project, and they will be recoverable via source control.
    • Temporarily erroneous scripts: should be (temporarily) fixed, that is the nature of programming / refactoring. If you don't and leave the script erroneous and disabled you will have a much harder time later to make that script work again. So keep it working instead, even if that means adding dummy methods or commenting some of its code.
    • Experimental scripts: should not cause compile errors to begin with. If they interfere with normal execution, make them disable-able, or untick/remove the component, or have an "experimental" prefab variant (or scene) that adds this experimental component which you can swap out easily.
     
    Last edited: Aug 8, 2023
  3. JGameMaker92

    JGameMaker92

    Joined:
    Oct 15, 2014
    Posts:
    83
    By allowing us to toggle a script's compilation, we'd have the freedom to iterate on ideas without getting bogged down in immediate error resolution. It could be an optional tool, something to enable when you need it without changing how things currently work for those who prefer the existing methods. Sometimes, it's handy to have an old script around without it getting in the way. Maybe it's for reference, or maybe you're not quite sure if you're done with it yet. Even if a script has errors it can still be useful. Having the option to toggle compilation off provides flexibility without permanent deletion. There could be situations where a script is in a transitional phase. You know it's not right yet, but you need to move on to something else temporarily. Disabling compilation for that script could be a neat solution to keep everything tidy without losing your work.
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    That's where source control branches come into play. You have a feature branch you work on, but then there's this really important bug you need to fix right now but you're in the middle of turning everything upside down and nothing is working. So you switch to the main branch, fix the bug, switch back to the feature branch and return to your work.

    All other purposes are just as easily solved by commenting the script, or parts of it.
     
  5. JGameMaker92

    JGameMaker92

    Joined:
    Oct 15, 2014
    Posts:
    83
    I still think we need a way to exclude scripts and even entire folders from being compiled. Especially when you can't build and run until all compiler errors are fixed. Maybe an asset got imported that has some errors in it and you want to disable it from being compiled for the time being, so you can still build your project without having to remove the entire thing. Many times I have to delete entire assets from my project just to be able to build and run again, and have to import them back just to figure out what's wrong with them. It's time consuming too having to do so messy work arounds when there could be an easier solution for excluding things from the compiler. There's so many instances where it would be useful. We deserve better than just having to comment things out or delete them.
     
  6. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    LOL, good to see that ChatGPT also knows nothing about software development.
     
  7. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    What kind of asset are you importing? Unless this asset contains scripts it should not cause compile errors.

    Could you describe by example one case what you import, the errors you get, the hings you have to fix to make it work? It seems to me that maybe you are following a workflow that is non-standard and that may be causing these issues to begin with.
     
  8. JGameMaker92

    JGameMaker92

    Joined:
    Oct 15, 2014
    Posts:
    83
  9. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    702
    "We deserve better than just having to comment things out or delete them."

    Who is "we"?

    This request doesnt make sense to me.

    Like how could you tell unity to ignore scripts, without it also having to ignore all dependencies.. ...and their dependencies? Its a mammoth task to ask of Unity for little to no gain.

    If it doesnt have dependencies, it is just as easy, if not easier to comment the script out, or you can even be more precise and comment out offenders... Or.. fix the bug.
     
    Lurking-Ninja likes this.
  10. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    Yay, a photoshopped context menu, there you go, there is your "feature". It's just as useful.