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.
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.
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?
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.
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.
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.
I was making up some new files to send along and I found that the way I make the file made a difference.
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.
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?
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.
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.