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?

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

  • Scriptname: not like an existing class!

    Don’t call your script ‘GUI’ or ‘Raycast’. Take a more unique name.

  • Scriptname: special characters may cause hickups

    Rather not call your script ‘Hy-phen’, ‘Some.dot’, ‘Under_score’ or ‘1NumberAtTheStart’

  • Extension must match content

    javascript-code in a .cs file?

    c#-code in a .js file?

get to the error

  1. click on the bottom-line of the unity-editor to open the console (= the log-file where you see debug-output, errormessages and warings).

    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.

  2. If you have compiler-errors, hit 'clear' just to be sure you only deal with the interesting parts.

    leave out this step, if you have runtime-errors!

  3. *read* the *first line* of the *first* error-message.

    Sometimes it’s very cryptic or misleading for a beginner but sometimes it acutally tells you straight out what you have to do.

  4. 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 this

Frequently 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

  • UCE0001: ';' expected. Insert a semicolon at the end

    Usually you miss a ‘;’ in the respective line,

    Or you have a ‘;’ too much in the code above,

    Or you missed {} around several stuff in a if-statement or loop

  • Script 'X' has not finished compilation yet. Please wait until compilation of the script has finished and try again.

    Check the link. SpikeX gives a good list of advice what to try.

  • Scripting MonoImporter Not Generating a md4digest

    You created a completely empty Scriptfile. This error should go away if you write some code or hit ‘clear’ in the console.

  • ScriptError: Update() can not be a coroutine.
  • expected EOF (='end of function'):

    you missed or missplaced a ’ } ’

  • JavaScript-Specific

  • BCE0004: Ambiguous reference.

    It’s unclear what you are referencing. It’s well explained here:

  • BCE0005: Unknown identifier 'X'.

    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/31996/unknown-identity-itween.html

  • BCE0011: An error occurred during the execution of the step 'X'

    A rare Error. Not enough information…

  • BCE0017: The best overload for the method 'X.(Y)' is not compatible with the argument list '(Z)'.

    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.

  • BCE0018: The name 'X' does not denote a valid type.

    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.

  • BCE0019: 'X' is not a member of 'Y'.

    This error sometimes has to do with variables/functions not being typed/type-casted correctly/at all.

    or missing the proper path to a variable

    (especially popular: X.position instead of X.transform.position)

  • BCE0020: An instance of type 'X' is required to access non static member 'Y'.

    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

  • BCE0021: Namespace 'X' not found, maybe you forgot to add an assembly reference?

    This error has something to do with mono-dlls and there are rumors that it appears in connection with unity-bugs.

  • BCE0022: Cannot convert 'X' to 'Y'.

    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.

  • BCE0023: No appropriate version of 'UnityEngine.X' for the argument list'(Y)' was found

    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.

  • BCE0034: Expressions in statements must only be executed for their side-effects

    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){}

  • BCE0043: Unexpected token: 'X'

    This roughly translates to ‘something bad happend somwhere around here’

    Sorry… Check the ‘general checklist’.

  • BCE0044: expecting 'X', found 'Y'

    Sometimes you are actually missing ‘X’ exactly in that place… but often enough it’s something else.

    Sorry… Check the ‘general checklist’.

  • BCE0048: Type 'X' does not support slicing.

    A rare Error. Not enough information…

  • BCE0051: Operator 'X' cannot be used with a left hand side of type 'Y' and right hand side of type 'Z'

    You may be trying to do (math) stuff with types that don’t match (e.g. multiply a GameObject with a Number)

    Or you try to do stuff with an undefined Variable

  • BCE0055: Internal compiler error: Cannot cast from source type to destination type.

    A rare Error. Not enough information…

  • BCE0070: Definition of 'X' depends on 'X' whose type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle.

    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

  • BCE0077: It is not possible to invoke an expression of type 'X'.

    Unity is trying to treat ‘X’ like a function (probably because you put () after it), but that doesn’t work.

  • BCE0089: Type 'X' already has a definition for 'Y'.

    In script ‘X’ you probably have two functions with the name ‘Y’.

    Remove or rename on of them.

  • C#-Specific

  • CS0019: Operator 'X' cannot be applied to operands of type 'Y' and 'Z'

    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?

  • CS0029: Cannot implicitly convert type 'X' to 'Y'

    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.

    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)

  • CS0101: The namespace 'X' already contains a definition for 'Y'

    Quote Peter G: You have multiple classes (scripts) with the same name. Change the name of one of them

  • CS0103: The name `X' does not exist in the current context

    Maybe you miss a namespace. (A ‘using System.Something;’ at the beginning of the Script)

    Or you did not extend from a proper class (normally ‘MonoBehaviour’)

  • CS0106: The modifier 'X' is not valid for this item.

    A rare error. Not really enough information.

  • CS0116: A namespace can only contain types and namespace declarations

    A rare error; Probably messed up {}

  • CS0117: 'X' does not contain a definition for 'Y'

    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.

    Maybe you named your script like a built-in class?

  • CS0119: Expression denotes a `type', where a variable, value or method group was expected

    You probably missed the ‘new’-keyword

  • CS0176: Static member `X' cannot be accessed with an instance reference, qualify it with a type name instead

    A rare Error.

  • CS0230: Type and identifier are both required in a foreach statement

    A rare error; a foreach-loop is missdefined. Maybe you want a simple for-loop anyway?

  • CS0246: The type or namespace name `X' could not be found. Are you missing a using directive or an assembly reference?

    You probably misspelled ‘X’

    ‘X’ denotes a Script that does not exist/has a different name

  • CS0266: Cannot implicitly convert type `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 :stuck_out_tongue:

  • CS0283: The type 'UnityEngine.X' cannot be declared const

    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

  • CS0308: The non-generic method 'X' cannot be used with type arguments.

    A rare Error.

  • CS0649Waring: Field is never assigned to, and will always have its default value 'X'

    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

  • CS1061: Type 'X' does not contain a definition for 'Y' and no extension method 'Y' of type 'X' could be found (are you missing a using directive or an assembly reference?)

    A rare error; the only one I found was because of a misspelling…

  • CS1519: Unexpected symbol 'X' in class, struct, or interface member declaration

    quite likely you missed a ’ ; ’ in the line above the error.

  • CS1520: Class, struct, or interface method must have a return type

    A rare error. The ones I found were due to misspelling.

  • CS1525: Unexpected symbol 'X'

    This roughly translates to ‘something bad happend somwhere around here’

    Sorry… Check the ‘general checklist’.

  • CS1526

    A rare error. Not enough information…

  • CS1612: A new expression requires () or [] after type

    A rare error. Not enough information…

  • CS2011: Unable to open response file: 'X'

    A rare error. Not enough information…

  • CS8025: Parsing error

    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!

General Checklist

  1. Scriptname: not like an existing class!

    Don’t call your script ‘GUI’ or ‘Raycast’. Take a unique name.

    http://answers.unity3d.com/questions/46651/networking-problem-please-help-javascript.html

  2. Scriptname: special characters may cause hickups

    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…)

  3. Extension must match content

    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

  4. case-sensitivity and typos (missed or added a letter; added a space)

    These are viciously hard to spot!

  5. check your {}- and ()-pairs!!
  6. mixed up ' . ' ' , ' and ' ; '
  7. missed a ' ; ' somewhere near the line where the error is thrown
  8. added a ' ; ' somewhere near the line where the error is thrown

    especially popular to happen after if(), for() and while().

    http://answers.unity3d.com/questions/56926/why-is-this-giving-me-an-error.html

  9. added //-comment (thus having stuff commented that is required, especially ' ; '

    http://answers.unity3d.com/questions/118785/when-i-try-to-run-the-island-demo-on-unity-3-i-get.html

  10. linebreak in a //-comment (thus having stuff not commented)

    http://answers.unity3d.com/questions/34937/script-wont-run-level-platformer-tutorial.html

  11. = instead of == when trying to compare stuff

    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

  12. == instead of = when trying to assign stuff

    http://answers.unity3d.com/questions/43143/help-expecting-found-problem.html

  13. Scripts (=Classes), Functions and Variables should always have unique Names.

    Don’t have a Script ‘DoSomething’ and a Function ‘DoSomething’.

    http://answers.unity3d.com/questions/23286/the-best-overload-for-the-method-unityengineobject.html#

  14. can't define a function inside another function

    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

  15. all referenced Scripts must exist and have the variables that are accessed.
  16. did not give a type to parameters in function-declarations or loops

    http://answers.unity3d.com/questions/21674/what-is-wrong-with-this-c-code-i-have.html#

  17. array missdefined

    http://answers.unity3d.com/questions/57669/error-with-array-declaration.html

  18. 'If' something 'else' should be done after 'if', you need 'else' :p

    http://answers.unity3d.com/questions/125965/correct-script.html

  19. Special characters in variable- or functionnames may cause hickups

    http://answers.unity3d.com/questions/54388/unexpected-token-.html

  20. Instantiating Prefabs just by calling their name does not work

    http://answers.unity3d.com/questions/154072/instantiate-coming-up-with-errors-for-unknown-reas.html

  21. Don't copy a Projectfolder inside your Projectfolder

    http://answers.unity3d.com/questions/56024/cant-start-must-fix-all-comiling-errors-oxfffd.html

  22. may not rename plugins and have to put them in the apropriate folder

    http://answers.unity3d.com/questions/31996/unknown-identity-itween.html

  23. c#-only: all functions need to be inside the class-{}

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! :slight_smile:

Greetz, Ky.

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

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.