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

Syntax error at line 1

Discussion in 'Shaders' started by Tzan, Oct 16, 2010.

  1. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    733
    Shader error in '': Parse error: syntax error at line 1

    I am creating a combination of DiffuseDetail and Specular shaders.
    I made it in 2.6 and looking at the new stuff I figured it would be easy.

    All I did was copy the Diffuse Detail code into a new file.
    I changed the name on line one, but even with the exact copy of the old file I still get this error.

    I shut down the programs and restarted several times.
    I could post code but really its just this line.

    Code (csharp):
    1. Shader "Diffuse Detail Spec" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _MainTex ("Base (RGB)", 2D) = "white" {}
    5.     _Detail ("Detail (RGB)", 2D) = "gray" {}
    6. }
    7.  
    8. SubShader {
    9.     Tags { "RenderType"="Opaque" }
    10.     LOD 250
    11.    
    12. CGPROGRAM
    13. #pragma surface surf Lambert
    14.  
    15. sampler2D _MainTex;
    16. sampler2D _Detail;
    17. float4 _Color;
    18.  
    19. struct Input {
    20.     float2 uv_MainTex;
    21.     float2 uv_Detail;
    22. };
    23.  
    24. void surf (Input IN, inout SurfaceOutput o) {
    25.     half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    26.     c.rgb *= tex2D(_Detail,IN.uv_Detail).rgb*2;
    27.     o.Albedo = c.rgb;
    28.     o.Alpha = c.a;
    29. }
    30. ENDCG
    31. }
    32.  
    33. Fallback "Diffuse"
    34. }
    35.  
    36.  
    The remaining lines are just the same as in the original. I havent even started editing yet.

    The shader compiles and I can open it. The line looks normal to me.
    The shader does not show up in the list when you try to assign it to a material.
    I wrote it in Visual C#2008.
    I started it as a new text file.
     
    Last edited: Oct 16, 2010
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    I've copied and pasted the code you've posted (on a Mac) and didn't get any errors. Could the issue be with line endings or other invisible characters in the original code?
     
  3. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    733
    I know its not the code, its something weird. I'll check what you mentioned.

    I do sometimes have a pop up about having a mix of line endings. But not while working on these. VS2008 does the opposite of the built in text editor I think. I have one more thing to try. I was going to try cutting the Unity source files into Notepad, and see how that works.

    I've made multiple shader files in VS and they were all broken like this.
    In 2.6 I never had a problem.

    Have to do some regular work first :)
     
  4. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I had this same kind of problem when trying to learn Cg. It made no sense; I fixed line endings, and ran automated checks for differences which turned up no results. This was in Unity iPhone so it's definitely not a new 3.0 issue.

    I've never had this kind of issue with fixed function ShaderLab, though.
     
  5. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    733
    I just had a few minutes and cut the code into Notepad... and it worked just fine.
    I then put the same code into VS2008 and it was broken. It compiles, but shows that error and wont display on the list of shaders.

    Tonight I'll poke around some more. Looks like I just wont be able to edit them in VS, no big deal.
     
  6. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    733
    Looks like I will be using UniSciTE to edit shaders.
    It just doesnt work in VS2008 express.
     
  7. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Please can you file a bug report for this (menu: Help > Report A Bug)? If possible, please attach one of the shader files that causes the problem.
     
  8. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    733
    Ok

    Its not really the code though.
    It only messes up when I save in VS2008 express
     
  9. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    It can't just be VS, because I've never used it, and as I said, I had the same problem.
     
  10. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    733
    Reported
    378899

    This gets weirder.

    I was making up some new files to send along and I found that the way I make the file made a difference.

    1. If I open the Unity source file for a builtin shader in VC# 2008 then edited that file, save as, then Unity 3 will compile and it works.

    2 If I cut and paste into a new empty editor window it wont work.
    VC#2008, right click on a folder in the project, Add>NewItem>TextFile (also Class file breaks), create it with a new name File.shader.
    Paste the code into it, add a number into the string on line one so its unique, save, click on Unity3 window, watch it fail. It will compile, you can see the compiled code looks fine.

    I know how stupid this sounds, but I repeated the steps several times.

    Crap, I was going to reference this thread in the bug report. Phone call interrupted my thinking.

    This is broken
    http://dl.dropbox.com/u/10454876/Bugs/VC2008.shader

    This works
    http://dl.dropbox.com/u/10454876/Bugs/VC2008_works.shader

    Cutting and pasting into NotePad works.

    edit:
    Win7, i7-920, radeon 5870
     
    Last edited: Oct 20, 2010
  11. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    733
    Ok I solved it :)

    Copying to the clipboard, pasting into VC#2008, save, creates a UTF-8 format file.
    Pasting into Notepad, NotePad++, UniSci, creates a ANSI format file.

    Unity 3 doesnt like getting a UTF-8 format SurfaceShader file.

    I downloaded NotePad++ just now and it displays the Encoding at the bottom of the window.
    I had two windows open, one good file and one bad, looking for hidden characters when I spotted the encoding formats.

    I converted the UTF-8 file to ANSI and it worked.

    From MSDN
    "The only character set supported by the clipboard is Unicode in its UTF-8 encoding."
    So some editors will convert this to ANSI and others like VC# will keep the UTF-8.

    Most of my C# code files are UTF-8 because I copy/paste the header information into the blank file. These files work fine.



    Should Unity3 be able to use UTF-8 files for Surface Shaders?

    (sent bug update and link to this post)
     
    Last edited: Oct 20, 2010
  12. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    Visual Studio's advanced save options:

    $1.PNG
    Parse error: syntax error at line 1

    $2.PNG
    Great success.
     
    Last edited: Nov 23, 2012
    Phuongnguyen1002, Tzan and SkyNetTX like this.
  13. Tzan

    Tzan

    Joined:
    Apr 5, 2009
    Posts:
    733
    I just had this error again and couldnt remember the cause, it was so long ago :)
    Looks like The Unity 4 shader system still doesnt like this.
    So after 30 min. I checked here.

    Thanks alexzzzz that works great!
     
    Last edited: Apr 30, 2013
  14. guojian0102

    guojian0102

    Joined:
    Sep 5, 2015
    Posts:
    1
    I found the same error in Unity5 on my Win7 x64 System.It seems like that Unity doesn't like CR Line Endings,you should change it into CR+LF or LF,both is OK.
    In MonoDevelop,just change it in your Project-Solution,Code Formatting,ShaderLab shader,I change the Line endings to Microsoft Windows,and it works.
     
  15. Tracy-Ma

    Tracy-Ma

    Joined:
    Nov 22, 2012
    Posts:
    21
    I got the same error when do
    Code (CSharp):
    1. meshMaterial = new Material("Diffuse");
    , which should be
    Code (CSharp):
    1. meshMaterial = new Material(Shader.Find("Diffuse"));
    Unity should improve the error message here.