- Home /
Stuff-is-going-wacky! Checklist - Compiler-Errors, Syntax-Errors
Compiler-Errors
Help, my game won't start!
Unity sais I have to fix all compiler-errors before I can play!
What's going on? How can I fix this?
Answer by SisterKy · Aug 10, 2011 at 10:43 PM
If non of this helps...
Make sure to check out the annotations of how to post a syntax-error-question at the end of this post!
before even looking at the script
Don't call your script 'GUI' or 'Raycast'. Take a more unique name.
Rather not call your script 'Hy-phen', 'Some.dot', 'Under_score' or '1NumberAtTheStart'
javascript-code in a .cs file?
c#-code in a .js file?
get to the error
Note: don't worry if you have millions of errors.
The amount of error-messages says little about how good or bad your code is!
often, a single problem makes the compiler throw hundreds of errors because it missreads subsequent lines of code that are actually ok.
once you solve that one issue they may disappear by the dozen.
On the other hand, if only a single error shows up that does not mean there's little wrong..
That might only be because that error is so bad that it stops the compiler from checking further.
That hides any amount of other errors who will show up as soon as you fix the first one.
leave out this step, if you have runtime-errors!
Sometimes it's very cryptic or misleading for a beginner but sometimes it acutally tells you straight out what you have to do.
Double-click on the error-message.
It opens the script and puts the cursor in the line where it gets the error.
(The error-message also tells you which line and position; that looks like so: (13,61), meaning Line 16, position 61)
Note: most of the times this is only a rough estimate of where the problem really is.
Compiler- & Syntax-Errors
'Compiler-Error' is more or less a synonym for 'Syntax-Error'
Compiler is the thing that translates your script into binary-code (the 010101101-stuff) that the computerhardware can work with
Syntax means the Grammar of a Script.
People are smart and usually can figure out the essence of a sentence based on vocabulary.
Computers, by contrast, are stupid. They need you to stick to grammar very strictly to get what you mean.
all the following explanations confuse you only ever more? This might lift some mysteries:
Scripting-superbasics
and maybe some of thisFrequently asked beginners questions
Errors and their most common causes
'Common', not 'exclusive' -> if this doesn't work for you, also check the 'general checklist' below!
Note: I just collected the information I found on UnityAnswers.
This is probably far from complete!
If you find something wrong or like to add stuff, please do!
General
Usually you miss a ';' in the respective line,
http://answers.unity3d.com/questions/14810/lerpz-tutorial-multiple-errorshelp.html
Or you have a ';' too much in the code above,
http://answers.unity3d.com/questions/24791/never-used-an-animation-script-before-please-help.html
Or you missed {} around several stuff in a if-statement or loop
http://answers.unity3d.com/questions/26921/c-error-with-if-statement.html
Check the link. SpikeX gives a good list of advice what to try.
You created a completely empty Scriptfile. This error should go away if you write some code or hit 'clear' in the console.
http://answers.unity3d.com/questions/29276/why-do-i-get-error-when-using-yield.html#
you missed or missplaced a ' } '
JavaScript-Specific
It's unclear what you are referencing. It's well explained here:
http://answers.unity3d.com/questions/37839/what-does-bce0004-ambiguous-reference-error-mean.html
You are trying to use a variable or function that has not been defined.
Most likely misspelled or forgot to declare 'X' properly.
or you did not define the path to 'X'
http://answers.unity3d.com/questions/51354/bce005-unknown-identifier-kdefaultraycastlayers.html
http://answers.unity3d.com/questions/31996/unknown-identity-itween.html
A rare Error. Not enough information...
You probably used function X with values of type Z but it only can take values of type Y.
Put your cursor at function X and hit F1 to see the ScriptReference what kind of values Y are possible.
Or if it's a self-defined function you have to change the possible input-parameters.
This means Unity can't find a Script with the Name 'X'.
Likes to happen when you try to make c# and javascript work together.
http://answers.unity3d.com/questions/49502/how-do-i-fix-following-errors-help-please.html
This error sometimes has to do with variables/functions not being typed/type-casted correctly/at all.
http://answers.unity3d.com/questions/46681/android-bce0019-error-with-unityengine.html
http://answers.unity3d.com/questions/57167/bce0019-mesh-is-not-a-member-of-unityenginecompone.html
or missing the proper path to a variable
(especially popular: X.position instead of X.transform.position)
http://answers.unity3d.com/questions/54135/is-not-a-member.html
most likely you spelled something with a lower-case first letter which should be upper-case.
e.g. gameObject which should be GameObject or particleEmitter which should be ParticleEmitter
http://answers.unity3d.com/questions/9613/accessing-non-static-members-in-a-static-function.html
http://answers.unity3d.com/questions/53251/missing-particleemitter-instance.html
This error has something to do with mono-dlls and there are rumors that it appears in connection with unity-bugs.
This probably means you are trying to do an operation in this line that requires type 'Y' to work, but your variable has type 'X'.
This can happen if you did not type your variable (correctly) right at the start.
You may try to cast the type with the as-operator.
You are calling some built-in function with wrong stuff in the ().
Looking in the Scriptreference for 'X' tells you what you can use.
(put your cursor at 'X' in the code and hit F1 to quick-find it in the Reference)
'(Y)' is telling you what you currently are using.
You probably missed '()' when calling a function or a loop or if-statement, e.g.
Application.Quit;
has to be Application.Quit();
if (a==b){} else if {}
has to be if (a==b){} else if (c==d){}
http://answers.unity3d.com/questions/29832/applicationquit.html
This roughly translates to 'something bad happend somwhere around here'
Sorry... Check the 'general checklist'.
Sometimes you are actually missing 'X' exactly in that place... but often enough it's something else.
Sorry... Check the 'general checklist'.
A rare Error. Not enough information...
You may be trying to do (math) stuff with types that don't match (e.g. multiply a GameObject with a Number)
http://answers.unity3d.com/questions/32581/fixing-a-bce0051-error.html
Or you try to do stuff with an undefined Variable
http://answers.unity3d.com/questions/145556/destroy-on-range-command.html
A rare Error. Not enough information...
This can occure when you use recursion (a function that calls itself)
Such a function has to be typed as IEnumerator or replaced by a while-loop
Unity is trying to treat 'X' like a function (probably because you put () after it), but that doesn't work.
http://answers.unity3d.com/questions/28731/help-bce0077-it-is-not-possible-to-invoke-an-expre.html
In script 'X' you probably have two functions with the name 'Y'.
Remove or rename on of them.
C#-Specific
Pretty self-explaining: The math-stuff you are trying to do can't be done with something of type Y and of type Z.
e.g. can't multiply transform.position (a Vector3) with transform.forward (another Vector3).
Maybe you typed one of the variables wrong?
You are trying to do something that can only be done with variables of type 'Y' but the variable us use has type 'X'
This error likes to pop up when you try
if(something)
and something is not of type boolean. http://answers.unity3d.com/questions/23866/compile-errors-for-script.html
Thanks to the error you already know what the type of 'something' actually is (e.g. float) so sometimes you can work around with something like
if(something != 0.0f)
Quote Peter G: You have multiple classes (scripts) with the same name. Change the name of one of them
http://answers.unity3d.com/questions/49502/how-do-i-fix-following-errors-help-please.html
X' does not exist in the current context</b> <br/>Maybe you miss a namespace. (A 'using System.Something;' at the beginning of the Script) <br/>http://answers.unity3d.com/questions/47551/my-c-script-give-me-an-error.html <br/>Or you did not extend from a proper class (normally 'MonoBehaviour') <br/>http://answers.unity3d.com/questions/130923/random-animation.html# </li><br/> <li><b><a href="http://answers.unity3d.com/questions/topics/cs0106.html?sort=votes"> CS0106</a>: The modifier 'X' is not valid for this item.</b> <br/>A rare error. Not really enough information. </li><br/> <li><b><a href="http://answers.unity3d.com/questions/topics/cs0116.html?sort=votes"> CS0116</a>: A namespace can only contain types and namespace declarations</b> <br/>A rare error; Probably messed up {} </li><br/> <li><b><a href="http://answers.unity3d.com/questions/topics/cs0117.html?sort=votes"> CS0117</a>: 'X' does not contain a definition for 'Y'</b> <br/>You are trying to access a Variable or Function 'Y' in a Script or built-in class 'X' but that class doesn't have that. <br/>Maybe you named your script like a built-in class? <br/>http://answers.unity3d.com/questions/141594/error-cs0117-resources-does-not-contain-a-definiti.html </li><br/> <li><b><a href="http://answers.unity3d.com/questions/topics/cs0119.html?sort=votes"> CS0119</a>: Expression denotes a
type', where a variable, value or method group was expected You probably missed the 'new'-keyword
http://answers.unity3d.com/questions/56352/set-the-position-of-a-transform-object.html
X' cannot be accessed with an instance reference</b>, qualify it with a type name instead <br/>A rare Error. </li><br/> <li><b><a href="http://answers.unity3d.com/questions/topics/cs0230.html?sort=votes"> CS0230</a>: Type and identifier are both required in a foreach statement</b> <br/>A rare error; a foreach-loop is missdefined. Maybe you want a simple for-loop anyway? </li><br/> <li><b><a href="http://answers.unity3d.com/questions/topics/cs0246.html?sort=votes"> CS0246</a>: The type or namespace name
X' could not be found. Are you missing a using directive or an assembly reference? You probably misspelled 'X'
http://answers.unity3d.com/questions/14223/error-cs0246-the-type-or-namespace-name-rect-could.html
'X' denotes a Script that does not exist/has a different name
http://answers.unity3d.com/questions/24915/script-compile-error-script-is-in-c.html
X' to
Y'. An explicit conversion exists (are you missing a cast?) A rare Error. You have variables of type 'X' but try to do stuff with them that can only be done to variables of type 'Y'.
But their types are not all that different (e.g. both number-types) and they can be converted. You just need to find out how :p
Quote Mike 3: Only the C# built-in types (excluding System.Object) may be declared as const.
You may want to look into readonly instead - very similar, but allows writing at construction time
A rare Error.
A rare Warning. Check out the post to get rid of it:
http://answers.unity3d.com/questions/60461/warning-cs0649-field-is-never-assigned-to-and-will.html
A rare error; the only one I found was because of a misspelling...
quite likely you missed a ' ; ' in the line above the error.
A rare error. The ones I found were due to misspelling.
This roughly translates to 'something bad happend somwhere around here'
Sorry... Check the 'general checklist'.
A rare error. Not enough information...
A rare error. Not enough information...
A rare error. Not enough information...
A problem with your class-definition.
Probably either missed your ()
http://answers.unity3d.com/questions/130009/whats-worng-with-this-please-answer.html
messed up your {}
http://answers.unity3d.com/questions/63129/unable-to-find-solution-for-errors.html
or you missed a ' ; ' in the lines above class-definition
http://answers.unity3d.com/questions/45371/what-does-error-mean-i-got-it-from-this-line-of-sc.html
Shader-Specific
C5013: profile does not support "for" statements and "for" could not be unrolled.
Quote Mike 3: 'Try using a higher shader profile, e.g. #pragma target 3.0
'
http://answers.unity3d.com/questions/17772/solved-cg-error-profile-does-not-support-for-state.html#
My error looks nothing like any of the above. Much more scary!
Probably something is wrong with your scale
http://answers.unity3d.com/questions/8276/what-causes-error-sh-maabbisvalid.html
http://answers.unity3d.com/questions/11016/what-does-slot-getlocalaabbisvalid-mean.html
You may have found a c/c++ error of the UnityEngine. Maybe you should file a report.
If you are lucky, it will go away if you restart.
General Checklist
Don't call your script 'GUI' or 'Raycast'. Take a unique name.
http://answers.unity3d.com/questions/46651/networking-problem-please-help-javascript.html
Rather not call your script 'Hy-phen', 'Some.dot', 'Under_score' or '1NumberAtTheStart'
(I'm not sure on the exact rules, but better save than sorry...)
javascript-code in a .cs file?
http://answers.unity3d.com/questions/21592/i-cant-figure-why-im-getting-a-parsing-error-with.html
http://answers.unity3d.com/questions/142523/parsing-error-no-idea-what-it-is-or-what-the-probl.html
c#-code in a .js file?
http://answers.unity3d.com/questions/48992/using-for-in-unity-script-help.html
http://answers.unity3d.com/questions/32814/unexpected-token-collider.html
shader- or any other code in a .cs or .js file?
http://answers.unity3d.com/questions/31856/unlitalpha-shader-script-not-working.html
http://answers.unity3d.com/questions/47286/unitymasterproject.html
These are viciously hard to spot!
- 'myVariable' is not the same as 'my Variable'
http://answers.unity3d.com/questions/149429/script-help.html - 'myVariable' is not the same as 'myvariable'
- 'myVariable' is not the same as 'myVriable'
- 'transform' is not the same as 'Transform'
http://answers.unity3d.com/questions/148876/uce0001-expected-insert-a-semicolon-at-the-end.html - 'update' is not the same as 'Update' ('update' is not wrong, but it won't set anything off!)
http://answers.unity3d.com/questions/64770/please-help-me-with-this-boolean.html
especially popular to happen after if(), for() and while().
http://answers.unity3d.com/questions/56926/why-is-this-giving-me-an-error.html
http://answers.unity3d.com/questions/118785/when-i-try-to-run-the-island-demo-on-unity-3-i-get.html
http://answers.unity3d.com/questions/34937/script-wont-run-level-platformer-tutorial.html
http://answers.unity3d.com/questions/46972/scripting-problem-with-if-statements.html http://answers.unity3d.com/questions/148876/uce0001-expected-insert-a-semicolon-at-the-end.html
http://answers.unity3d.com/questions/43143/help-expecting-found-problem.html
Don't have a Script 'DoSomething' and a Function 'DoSomething'.
http://answers.unity3d.com/questions/23286/the-best-overload-for-the-method-unityengineobject.html#
function Update() { function MyFunction(){} }
doesn't work http://answers.unity3d.com/questions/30200/help-me-debug-this-code.html
http://answers.unity3d.com/questions/34283/could-someone-tell-me-whats-wrong-with-this-script.html
http://answers.unity3d.com/questions/21674/what-is-wrong-with-this-c-code-i-have.html#
http://answers.unity3d.com/questions/57669/error-with-array-declaration.html
http://answers.unity3d.com/questions/125965/correct-script.html
http://answers.unity3d.com/questions/54388/unexpected-token-.html
http://answers.unity3d.com/questions/154072/instantiate-coming-up-with-errors-for-unknown-reas.html
http://answers.unity3d.com/questions/31996/unknown-identity-itween.html
Posting a Question when having a Compiler-Error
Title should contain:
- language (c#, javascript or boo)
- what error (not the code-name but something along the line 'compiler-error: found , expected .' etc.) Note: When dealing with errors, especially compiler-errors, it does not matter what the script is supposed to do.
Fixing grammar is always the same, no matter the genre or subject.
e.g. it does not matter if your script is about flying or taking the dog for a walk.
if a ' ; ' is missing, a ' ; ' is missing.
You can, however, mention what kind of vocabulary is going wrong, e.g. 'arrays', 'for-loop', 'hashtable' etc.
Tags should contain
- 'error'
- 'syntax-error'
- '[error-code]' (e.g. 'bce0044');
- additional Tags as needed.
Question should contain:
- Complete first line of the first errormessage
- Scriptname and Extension
- what language you are using code
- select the code and hit the 101010-button to format
- Mark the exact line, where the error occures. e.g.:
var backgroundStyle : GUIStyle = new GUIStyle() /**** <- ERROR happening HERE ****/
- If it's a short script, post it completely
- If it's very long, only post sniplets; add if asked for more
- tell that you only posted a sniplet!
- roughly describe where the code is (e.g. 'inside a for-loop in function Update' etc)
- Be sure to add at least a few lines of code above and below the line where the error occures.
- If the error is about a variable, add the line where it is defined.
Good hunting! :)
Greetz, Ky.
Answer by GameDaddy · Apr 08, 2012 at 01:00 AM
Error CS1526 update:
I fixed this by adding a semicolon to the end of the variable declaration located on the line immediately above the line the mono editor said was failing to compile...
Cheers! GameDaddy
Answer by PigsInACoffin · Sep 19, 2013 at 01:00 AM
For CS2011: Unable to open response file: 'X'
Since this is a more ambiguous compile error, I will post my use case.
My use case: when I added a C# script file , I would get a compile error
My fix: I created the project in a public folder instead of a private folder.
basically, it was a permissions issue.