I’m using Unity 3D in combination with Visual Studio 2008 on a Windows 7 64 bit system.
When saving a cs file in Visual Studio and returning to Unity 3D I always get the following warning:
There are inconsistent line endings in the ‘someFileName.cs’ script. Some are Mac OS X (UNIX) and some are Windows. This might lead to incorrect line numbers in stacktraces and compiler errors. Unitron and other text editors can fix this using Convert Line Endings menu commands.
I’ve seen that more people have this problem but they all are using OS X.
How can I fix this problem on my Windows machine?
UPDATE:
OK, I fixed the problem by replacing the NewBehaviourScript.cs that is located in Unity\Editor\Data\Resources
By creating a new script using Windows it contains only CrLf for new lines. So now when I create a new cs script in Unity and edit it in Visual Studio all the line endings are the same. So no more warnings
Good fix. I had been changing the newlines each time I created a new script, didn’t realize the template script was somewhere I could edit once and for all.
John C>
“For all your days, prepare, and meet them ever alike;
When you are the anvil, bear - when the hammer, strike.”
Create a new class in visual studio and set it up in the same way as the default NewBehaviourScript.cs.
Do not copy and paste as you will most likely copy the line endings too, thus undoing your efforts.
It is possible Unity does this so that other OS’s IDE’s ‘understand’ the script too.
Line endings by the way are the characters that text editors interpret as a new line. “/n” or “/r” for example.
IMO the best solution for this problem is not to change the default Monobehaviour script, as in the case you want to share the project, it means you have to ensure they have the same setup as you, or change their default line endings in mono etc which will only hassle potential team mates. Instead what I did was get an addon for VS called “Strip’em”(grebulon.com), it allows you the option to force Unix (the default mono) line endings on save (without having to change settings each time).
The easiest way to change the line endings without having to modify anything in VS is to go to the File > Advanced Save Options. In the Advanced Save Options window, under Line endings drop down, select the line ending you want to use and click OK. Then save the script again; this will automatically change the line endings in your script when you save it. When you go back into Unity, the error will disappear.
Finally, no more popups in Visual Studio! I already knew of the script templates, but last time I was only looking to add common using directives like System.Collections.Generic. I wasn’t paying attention to how the code was clumped up on one line, a sure giveaway that the template had non-Windows endings. I just upgraded to 4.6 and had to edit the template again when it finally hit me.
I’m using VisualStudio 2012 to write my scripts and I used to get these warnings.
To solve the problem just go to your scripts in VS and do: Edit > Advanced > Format Document
To elaborate on this technique, it does work, but it will only apply to the current file. There unfortunately does not seem to be a per project line ending setting built in (at least in the free Visual Studio 2013), which is why people are using the Strip’em add-in linked above.
Note that this add-in sets the line endings globally (all files, all projects), so you would need to disable/enable it if you’re switching between projects that have both Windows and Linux line endings. Strip-em it is!
This. Thank you, this is what I was looking for, and it fixes the problem, without using any workarounds, and you can still have a mixed team of Mac and Windows developers working together.
EDIT: Damn! Seems I was partying too soon. As others wrote, this setting does not appear to be permanent, is maybe on a per-file basis, and even if I re-open “Advanced Save Options” immediatly, it doesn’t show the setting I chose, but merely says “Current Setting”, without stating what that setting is.
To make a long story short, I now also installed Stick’em. The only weird thing seems to be that now the files are saved as ASCII, not as UTF-8. But that should be OK for source code.