Compiler errors and warnings

Compiler messages will fill the Console window whenever the project game scripts are recompiled, which may happen as a result of an asset import or script change. The more severe compiler errors will block your ability to run the project in the editor. Warnings are more benign and less critical, but it is equally important to observe when they happen. The following list covers some of the more common errors and warnings you may encounter:

  • Compiler Errors: These will show up as red text in the status bar or with an error icon in the Console:
    • Syntax error: This is likely the most common error you will encounter. Double-click on the issue to open the script to the point of the error in your editor. Simply edit the script to fix the syntax issue.
    • Missing script: This is a nasty issue that can occur when importing assets--a script may have moved or there could be a naming conflict. A missing or broken script will be removed as a component from any game object. You will either want to correct the issue by reimporting broken assets or managing the name conflict.
    • Internal compiler error: This is another nasty error that can be difficult to diagnose. It is more common if you are using plugins, but may also occur if you alter method signatures. Try to isolate where the issue is occurring and check your use of methods or parameters.
  • Compiler Warnings: These appear as yellowish text in the status bar, or with a warning icon in the Console. Double-click on any warning to be taken to the offending code in your editor of choice:
    • Obsolete code: Unity will flag code that is using properties or methods that have been deprecated. This can be a common issue if you use older assets not released for your version of Unity. You will need to update the code to use the new method in order to remove the warning.
    • Inconsistent line endings: This is an annoying warning that may occur from switching editors or importing code. Fix the issue in your code editor by setting consistent line endings by navigating to MonoDevelop: Project | Solution Options | Source Code | Code Formatting, Visual Studio: File | Advanced Settings.
    • General warnings: This is like unused fields or variables, not critical, but something to clean up when your game or scripts are ready for release.

Note

There is a way to turn compiler warnings into errors and thus force all warnings to be fixed. While this may be a preference for some developers, it is not recommended as the best practice.

A good habit to get into is to clear the Console window before script editing or asset importing. That way it is easier to track and filter compiler issues. After you fix those compiler issues, it becomes time to track down any runtime errors or warnings, which we will cover in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.119.17