10
\$\begingroup\$

Everytime I open a script file from unity with visual studio this dialog shows up about normalizing the line endings? What does this mean? I click Yes every time but still can't get rid of it. It only happens when I open a file from unity.

enter image description here

\$\endgroup\$
  • 5
    \$\begingroup\$ Unity's default script & shader template files have Unix/Mac-style line endings in them (LF), but Visual Studio in Windows likes working with Windows-style (CR LF). It usually goes away once you've normalized each file once and saved the result. I keep telling myself I'm going to go in & edit all the templates so I never need to deal with this again, and then I keep not doing it... (I really wish Unity would just match the convention of the OS or [expose an option to] always silently auto-convert. The constant prompts are really annoying) \$\endgroup\$ – DMGregory Mar 3 '17 at 15:57
  • \$\begingroup\$ ...or switch to VS Code. There is even a Unity Asset Store plugin for it: assetstore.unity.com/packages/tools/vscode-45320 \$\endgroup\$ – Jasper Citi Jul 5 '19 at 4:58
  • \$\begingroup\$ visual studio fix this error .. problem fixed here \$\endgroup\$ – Ahmed Aniss Aug 1 at 12:29
  • \$\begingroup\$ @AhmedAniss please stop this. Your answer is a link only one and should not be posted as an answer. \$\endgroup\$ – Vaillancourt Aug 1 at 12:43
5
\$\begingroup\$

In Visual Studio, you can disable this check (and thus the warning) by looking in Tools -> Options, navigating to the Environment -> Documents section of the tree, and unchecking "Check for consistent line endings on load."

This suppresses the warning but doesn't actually solve the problem; the source files will still have inconsistent line endings. Ideally you'd solve this problem by configure all the editors you use to insert the same kind of line ending, or to autodetect the existing style and preserve it. Unfortunately not all text editors support such behavior; VS, for example, doesn't have a controllable default (although it will let you configure the style used on a per file basis on File -> Advanced Save Options, but this is really tedious).

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ thx for the help... i think developers of these tools dont get many complaints about this so they never fixed such an annoying behaviour \$\endgroup\$ – Mark S Mar 3 '17 at 19:44
7
\$\begingroup\$

End-of-file (EOF) | Line ending, end of line (EOL)

As Josh Petrie mention, you can solve the problem by changing the line endings of each script you open. First, you need to close the script in Visual Studio. Then go to Unity and double click in the Unity console line ending warning message. Visual Studio will open the script with the missing and a line ending dialogue window will show up. Go to the Line endings section and choose Windows or the OS platform that you are using. Now save the script and next time you open VS, the message will not pop up for this script.

Visual Studio 2019

If it is not working as a workaround you can force normalize using

  • Edit > Advanced > Set New line > CRLF (for Windows).

This will replace all LF to CRLF.

DEFAULT TEMPLATE

When you make a new script the template can have an incorrect line ending. So if you change the Unity template, each time you make a new script you will not encounter this common problem. To change the default template go where Unity was installed and search for the ScriptTemplates folder:

C:\Program Files\Unity... Hub\Editor\20xx.x... Editor\Data\Resources\ScriptTemplates

In Windows, the default template script can be modified as administrator or using admin password. Now open this script template with VS (file: 81-C# Script-...). In VS with the script selected, go to File -> Advanced Save Options, the window will pop up and choose Windows or the platform OS that you are using. Now save the script and next time you make a new C# script in Unity, the message will not pop up for all this new scripts.

INSTALLING Strip'em for VS 2010-2017

Now you can also test if you wish this other tools for VS. This old video (at 10m32s) can help you in the process, but the rest of the video is already outdated. Warning, don't follow this tutorial, it doesn't work anymore. It helps you in the process of using Strip'em (after 10m32s)

https://youtu.be/2PVPz8Pnnrw?t=10m32s

To activate Strip'em in VS 2015, after the installation, press Tools > Strip'em and select your OS. Strip'em in VS Community 2017, you just double-click the installer and that is all.

http://www.grebulon.com/software/stripem.php

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Unless you're extremely committed to Visual Studio, I've found that literally just opening the file in another text editor (like Sublime or VS Code) and then saving it immediately fixed the issue. I've had poor experiences with Visual Studio in the past, and it's always extremely hard to debug weird editor errors.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.