Search Unity

inconsistent line endings

Discussion in 'Scripting' started by hjbaard, Feb 6, 2010.

  1. hjbaard

    hjbaard

    Joined:
    Feb 5, 2010
    Posts:
    38
    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 :)
     
  2. Cyclops

    Cyclops

    Joined:
    Jan 31, 2010
    Posts:
    111
    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."
     
    lolgamer_ro likes this.
  3. PatHightree

    PatHightree

    Joined:
    Aug 18, 2009
    Posts:
    259
    Awesome, I wish I could upvote this.
    Thanks for sharing :)
     
  4. LVBen

    LVBen

    Joined:
    Apr 1, 2013
    Posts:
    16
    Sweet!
     
  5. acollins

    acollins

    Joined:
    Jan 12, 2014
    Posts:
    1
    What do you mean by "creating a new script using Windows it contains only CrLf for new lines"? How do you actually do this?
     
  6. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    959
    I assume you just have to open the NewBehaviourScript.cs script in VS, and then save it.
     
    Muntaha_Islam likes this.
  7. LEDWORKS

    LEDWORKS

    Joined:
    Mar 14, 2012
    Posts:
    5
    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.
     
    Last edited: Apr 1, 2014
  8. grimprophecy

    grimprophecy

    Joined:
    Apr 18, 2013
    Posts:
    2
    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"(http://www.grebulon.com/software/stripem.php), it allows you the option to force Unix (the default mono) line endings on save (without having to change settings each time).
     
    olgapavldobrovol, Aggressor and jwinn like this.
  9. BrilliantOne

    BrilliantOne

    Joined:
    Aug 10, 2014
    Posts:
    4
    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.
     
    khanhabib, dbchest, Merman and 38 others like this.
  10. Valvados

    Valvados

    Joined:
    Jan 27, 2013
    Posts:
    60
    prefer to change the C# template as it has not neat formatting anyway.
     
    Harinezumi likes this.
  11. BlackPanda

    BlackPanda

    Joined:
    Jan 24, 2014
    Posts:
    76
    In VS 2013, reopen the file in VS itself and a popup will ask you to convert line endings. Just select crlf there.
     
  12. BrianCrandell

    BrianCrandell

    Joined:
    Apr 3, 2013
    Posts:
    63
    OMG, 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 didn't pay enough attention to the fact that the code was clumped on one line, an obvious giveaway that the template itself has non-Windows line endings. I just upgraded to 4.6 and had to edit the template again, when it finally hit me. Yay!
     
  13. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Just use stripem, or if you know only windows users using vs will be editing you could also change the template.

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

    I opted to just use stripem to force unix style endings since some people I work with use mono, and that I will sometimes use gvim to do fast edits.

    Also a other option is most version control systems like git, can enforce a certain kinda kind ending on commit.
     
    Last edited: Jan 14, 2015
    Yaten Kou, jwinn and BrianCrandell like this.
  14. Elixir

    Elixir

    Joined:
    Nov 30, 2013
    Posts:
    2
    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

    That will stop the warnings.
     
    SummerWolf, dimmu27, Merman and 6 others like this.
  15. Jeromeyers

    Jeromeyers

    Joined:
    Feb 1, 2015
    Posts:
    4
    Awesome, I love the direct fixing of the line endings in the script template. Both addresses the problem at the root and opens up new possibilities!
     
  16. meowFlute

    meowFlute

    Joined:
    Apr 19, 2015
    Posts:
    1
  17. jwinn

    jwinn

    Joined:
    Sep 1, 2012
    Posts:
    72
    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!
     
  18. Wolfram

    Wolfram

    Joined:
    Feb 16, 2010
    Posts:
    163
    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.
     
    Last edited: Sep 18, 2015
  19. Mattias_Timonen

    Mattias_Timonen

    Joined:
    Sep 19, 2015
    Posts:
    1
    That's the kind of solution we wanted to see! Using the options at hand without the need for downloading scritps and add-in's or whatever. thank you!
     
  20. dlqx

    dlqx

    Joined:
    Oct 12, 2013
    Posts:
    1
    thanks, that's the trick :)
     
  21. Toadwolf

    Toadwolf

    Joined:
    Sep 4, 2014
    Posts:
    9
    If you are looking for NewBehaviourScript.cs in order to change the line endings permanently (which is my preferred solution), the name and location has changed. It is now

    Editor\Data\Resources\ScriptTemplates\81-C# Script-NewBehaviourScript.cs.txt

    You can change the line endings as described above using Visual Studio, or in Notepad++ using Edit > Format Line Endings > Convert to ... (whatever you prefer).
     
    EbalStudios, Alverik and LeftyRighty like this.
  22. Yaten Kou

    Yaten Kou

    Joined:
    Dec 10, 2015
    Posts:
    1
    SWEEEEET!!!
     
  23. YahooAnswers

    YahooAnswers

    Joined:
    Feb 9, 2016
    Posts:
    2
    Thank you! This is the most sensible suggestion here.
     
  24. VamossVoar

    VamossVoar

    Joined:
    Oct 24, 2014
    Posts:
    4
    In Visual Studio 2012:
    File
    > Advanced Save Options
    In "Line endings" select "Unix (LF)"
     
  25. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    notepad++ have moved the option for this, it's now: "edit > EOL conversion > <whateveryouwant> format"
     
  26. scortillion

    scortillion

    Joined:
    Nov 24, 2015
    Posts:
    4
    I prefer this answer, thanks.
     
  27. Mortalanimal

    Mortalanimal

    Joined:
    Jun 7, 2014
    Posts:
    279
    In Visual Studio 2015:

    ToolOptionsEnvironmentsDocumentsCheck for consistent line ending on load.

    It will then propose you to convert line ending on opening. Then just open the files and save them.

    This worked for me, never got the error again
     
    lliF, etzl, MessinaTalia and 3 others like this.
  28. lmov

    lmov

    Joined:
    Dec 31, 2016
    Posts:
    1
    Great Solution!! very good!!
     
  29. yagodar

    yagodar

    Joined:
    Oct 10, 2016
    Posts:
    6
    omg! awesome solution! you saved my days in change Advanced Save Options each time I create script!! :):):)
     
  30. HobbyBobby

    HobbyBobby

    Joined:
    Jan 24, 2017
    Posts:
    1
    Thank you, that fixed it in my Visual Studio 2010.
     
  31. Govind-Krishna

    Govind-Krishna

    Joined:
    Jul 10, 2015
    Posts:
    5
    Thank you so much! This helped
     
  32. TokyoDan

    TokyoDan

    Joined:
    Jun 16, 2012
    Posts:
    1,080
    Strin'em is supposed to do the trick. If you don't like it you can uninstall it vis the Tools->Extensions and Updates Installed tab.
     
  33. MetricsGaming

    MetricsGaming

    Joined:
    Dec 21, 2016
    Posts:
    2
    But I cannot save the text document in Unity\Editor\Data\Resources\ScriptTemplates in unity5.6beta

     
  34. synapsemassage

    synapsemassage

    Joined:
    Jul 27, 2009
    Posts:
    333
    To save this file you need to execute visual studio with administrator rights.
     
  35. hoyle-a

    hoyle-a

    Joined:
    May 17, 2017
    Posts:
    1
    Thanks for this information. The add-in you mentioned was not compatible with Visual Studio 2017, so for those in the same boat i found this add-in on the Visual Studio Marketplace and it installed and seems to work like a charm. Line Endings Unifier by Jakub Bielawa
    https://marketplace.visualstudio.com/items?itemName=JakubBielawa.LineEndingsUnifier
     
    Last edited: May 17, 2017
    Denis1701 likes this.
  36. Mr_Jun

    Mr_Jun

    Joined:
    Jun 18, 2017
    Posts:
    1
    But I could'nt find Advanced Sace Options in visual studio
     
  37. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    802
    If you are on VS 2017 I dont think its there any more.
    Seek another solution, there are more posted in this thread.
     
  38. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    it's just in the "save as" options now (not that that makes much sense...)

    upload_2017-6-20_18-51-37.png
     
    azsilver likes this.
  39. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    802
    Ah nice catch, I would never have seen that.
     
  40. gig6

    gig6

    Joined:
    Jun 27, 2017
    Posts:
    1

    Just opening the script with Visual Studio in the directory above and saving it (no changes to the file) fixed the problem for me.
     
    Last edited: Jun 28, 2017
    etzl likes this.
  41. churi24

    churi24

    Joined:
    Sep 17, 2013
    Posts:
    78
    File>Advanced Save Settings on Line Ending -> Windows (CR LF)
     
  42. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,884
    Edit: Actually, I was wrong. Here's the real cause:

    Here's another annoying case. If you create a .shader file that's saved with Windows line endings and Unity modifies it silently by changing some code, for example, // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)', the changes made by Unity will have Unix/OSX line endings while the rest stays Windows.

    Even if you use preprocessor #ifs to denote that some code is for an older version of Unity (for example in a product on the Asset Store), Unity will still "upgrade" the code inside the #if. The only solution if you have a shader that has to support old versions of Unity is to save it with Unix/OSX line endings so the upgrade doesn't trigger the warning. :rolleyes:
     
    Last edited: Jul 17, 2017
  43. RyanFavale

    RyanFavale

    Joined:
    May 30, 2014
    Posts:
    28
    Awesome. Thank you!
     
  44. jeremytm

    jeremytm

    Joined:
    Jun 6, 2016
    Posts:
    28
    Hey everyone. We have a team where some of us are using Mac and some are using Windows. As someone on a Mac, when I update to the latest project code via Unity Collab, Unity automatically updates certain files, usually meta files and especially editor related files and converts the line endings to Mac/Unix.

    This results in many files being marked as changed, and ready to publish.

    How can I set Unity to either:

    1. not care about line endings, or
    2. don't change line endings from DOS to Unix, or
    3. only use DOS line endings if Unity really must update certain files

    (More of the team uses Windows than Mac so we may as well stick with Windows).
     
  45. Stomplab

    Stomplab

    Joined:
    Jul 24, 2014
    Posts:
    1
    open your file in visual studio, a pop-up will ask you what line endings you want to use. Simply chose Windows and make sure that the "show each time" box is ticked.
     
  46. isrra007

    isrra007

    Joined:
    Nov 20, 2017
    Posts:
    1
    elnaggaraya97 likes this.
  47. JackofTraes

    JackofTraes

    Joined:
    May 28, 2014
    Posts:
    10
    Uhh...there is a much easier fix. Rather than using plugins or manually saving each file, do the following.

    At the start of your Unity project, simply follow this path:

    Edit > Project Settings > Editor > Line Endings For New Scripts (bottom of list in the inspector)

    Then choose what you want in drop-down menu. I'd imagine that most would need "Windows" option. For me, this solved my problems in a matter of seconds - no downloads or file editing required. Hope this helps.
     
  48. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,466
    What version of Unity do you use? Because I don't see this.

    What I usually do to fix this very annoying problem is go onto Advanced Save Options in Visual Studio, select Line Endings, then save the script.
     
  49. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    3,884
    This is great to know, but you do realize this is a brand new feature? Look at the docs page for 2017.2:
    https://docs.unity3d.com/2017.2/Documentation/Manual/class-EditorManager.html

    Then 2017.3 version:
    https://docs.unity3d.com/2017.3/Documentation/Manual/class-EditorManager.html

    The last post in this thread was before 2017.3 was even out.
     
    Ian094 likes this.
  50. JackofTraes

    JackofTraes

    Joined:
    May 28, 2014
    Posts:
    10
    I am currently using 2017.3.0f3 and it should be at the bottom of the following list:
     
    wlwlz, Merman, jmandak and 1 other person like this.