Script Editor

Introduction

Godot Engine's script editor is a powerful and fully-integrated text editorthat not only streamlines the process of writing and debugging code written inGDScript but also allows for working with plain text files, providingdevelopers with a seamless environment for scripting game logic and behaviors.It can highlight your code, automatically indent it, perform syntax checks,and much more.You can also create breakpoints to debug your project without switching toanother window.The text editor also serves as an offline class reference viewer, which canbe accessed in several ways as described in theIntegrated class reference.

../../_images/text_editor.webp

Features

Some of the key features of the text editor are listed below:

  • Fully-integrated code editor for GDScript.

  • Syntax highlighting support for GDScript and JSON files.

  • Syntax checking for GDScript and JSON files.

  • Bookmark and breakpoint support.

  • Automatic indentation.

  • Code folding.

  • Customizable theme.

  • Multiple carets, which can be enabled usingAlt+LeftClick.

  • Auto-completion of variables, functions, constants, etc.

  • Inline refactoring of symbols by selecting them and usingCtrl+D.

  • Mass find and replace across project files.

Usage

If you are using GDScript in your project, the built-in text editor inGodot provides everything you need, serving as a one-stop location tofully utilize the Godot Engine. Nearly all parameters that can be adjusted viathe user interface can also be modified directly through code.

Note

If you would like to use an external text editor or prefer to use C#in your project, seeUsing an external text editor andConfiguring an external editor.

Tip

Similar to many parts of the Godot's interface, the text editor canalso be customized by changing its settings to your liking. You can accessthese settings by openingEditor > Editor Settings and going to theText Editorgroup.

../../_images/editor_ui_script_editor_open.webp

You can open the Script Editor using theScript button in the workspace selector,located at the top center of Godot's interface.Alternatively, you can use theOpen Script button next to a node in theScene Tree dock, or double-click on a.gd file or a recognized text file inthe FileSystem dock to open it directly in the Script Editor.

../../_images/editor_ui_script_editor_menu.webp

Once it is open, you will see the text editor menus at the top, below the sceneswitcher. Next to the menus, you'll find buttons to open the online documentationor search within the built-in class reference. To the right of these buttons aretwo navigation arrows that allow you to navigate through your viewing history.Finally, you can use the float button toseparate the text editor from Godot's window, which is useful if you are workingwith multiple monitors.

Underneath the menus on the left, you will see the script panel. In the center,adjacent to the script panel, is the coding area. Beneath the coding area is thestatus bar, which displays the error and warning count in the code.Clicking on the error or warning icons will show the list of errors withthe line numbers. Clicking on one will jump to that line.You can also choose to ignore warnings by opening the list andclickingIgnore.The status bar also lets you change the zoom level of the code by clickingthe percentage value. You can also useCtrl+MouseWheel(Cmd+MouseWheel on Mac) to achieve the same effect.The status bar also shows the current position of the caret in terms of line andcolumn, and whether the indentation is done using tabs, or spaces.

Many of the actions performed in the text editor can also be executed usingshortcuts. The actions show their corresponding shortcuts next to them.For a complete shortcut list, see thetext editor shortcuts.

In the next sections, we will go through different aspects of the text editor.You can also select a section below to jump to a specific topic:

Script Panel

../../_images/editor_ui_script_editor_script_panel.webp

Below the menus, on the left panel, you will see a list of opened files and documentationpages. Depending on the file type, this list will have an icon nextto the file name. For example, thescript icon means that it is a GDScript.thescriptcsharp means it is a C# script. Thedocumentation means that this is abuilt-in class reference. Finally, thetoolscript means it is a currently runningscript (Seetool annotation for more on this).Hovering a file will show a tooltip with its relative location in the project folder.

On the status bar, clicking the left arrow hides the script panel, clickingon the right arrow shows it.

If you did not change any settings, the file names may also have a different coloring.This helps you identify the recently edited files by highlighting them. This behaviorcan be changed in theEditor > Editor Settings by adjusting theScript Temperatureproperties in theText Editor section.

The filter bar above the file names introduces a handy case-insensitive search tofind a specific file. Even if you just type the letters of a file name into thebar, files containing these letters in order will also appear. Assume that thereis a file namedbutton.gd in the list. If you typebtn into the filter bar,this file will appear in the results. To reset the filter, clear the filter bar.

An asterisk (*) next to a file name indicates that the file has unsaved changes.

Tip

If you just enter "*" in the filter bar, you can display all unsaved files.

You can drag a file to change the ordering. Middle-clicking on a file closes it.Right-clicking on a file provides several options to save or close files, or tocopy the relative path of the file. On this menu:

You can also useMove Up andMove Down to change the order of the file, or useSortto sort all files alphabetically.Toggle Scripts Panel hides the panel, whichcan be displayed again using the right arrow on the status bar.Close Docs closes all opened in-class reference documents leaving onlyscript files open.Show in FileSystem finds and highlights the file in theFileSystem dock.

Below the file list, you'll see the name of the currently open file. The buttonnext to this switches the ordering of the methods defined in this file betweenalphabetical and as they appear. Under this is the outline of the file. If thisis a script file, it will contain the list of defined methods. If, however, aclass reference page is open, this area will show the table of contents of thisdocument. Clicking on an item in this list will jump to the respective functionor section in the file. Similarly, theFilter Methods bar lets you searchfor a specific function or section within the selected document with the samebehavior as filtering scripts.

Menus

The text editor's menus lie below the scene switcher and allow you to access avariety of tools and options, such as file management, search and replace, debuggingcontrols, and code formatting features.

Tip

An asterisk (*) next to an action means that this operation is also availablein the context menu, which can be opened by right-clicking in the code editor.

../../_images/text_editor_menu.webp

TheFile menu provides the following options:

../../_images/text_editor_file_menu.webp
  • New Script...: Opens the new script dialog to create and add the script tothe project. If creation is successful, it will directly open it in thetext editor. Depending on the version of Godot (with C# support or not), youcan choose.gd or.cs as the extension.

  • New Text File...: Opens the file dialog to create a plain text file withone of the recognized formats. Godot can also highlightjson files.

  • Open...: Opens the file dialog to let you browse inside your computer andchoose any recognized text file to open it.

  • Reopen Closed Script: Reopens the last closed scripts. You can use thisoption multiple times to reopen other closed scripts if you closed more than one.

  • Open Recent: Provides a list of last opened scripts. You can also clear thelist using the provided option at the bottom of the list.

  • Save: Saves the currently selected script.

  • Save As...: Opens the file dialog to save the currently open scriptwith a different name.

  • Save All: Saves all unsaved open scripts in the text editor. Scripts withunsaved changes will have an asterisk (*) next to their names in the script list.

  • Soft Reload Tool Script: If the selected script is atool, reloads the script to execute it again.

  • Copy Script Path: Copies the currently selected script's relative path inthe project using theres:// prefix.

  • Show in FileSystem: Finds and highlights the selected file in the FileSystemdock.

  • History Previous: Changes the active script to the one that was previouslyopened. This is useful when you have multiple scripts open and want to quickly navigateback to the last script you were editing. If you also changed the caret position more than10 lines, you will first move it to its previous location in the same file.

  • History Next: After usingHistory Previous to go back to an earlier script,this feature allows you to move forward through the script history, switching toscripts that were previously accessed. Similar to above, if you also changed thecaret position more than 10 lines, you will first move it to its next location inthe same file.

  • Theme: Provides options to import an existing theme, save, or reload it. Changingtheme settings is performed viaEditor Settings.

  • Close: Closes the active script.

  • Close All: Closes all open scripts and prompts to save if there are unsaved changes.

  • Close Other Tabs: Closes all open scripts except the selected one.

  • Close Docs: Closes the class reference documentation pages, leaving only thescripts.

  • Run: If the script extendsEditorScript andintended to be executed without running the project, this option runs the script.SeeRunning one-off scripts using EditorScript for more.

  • Toggle Scripts Panel: Shows or hides the script panel located on the left sideof the text editor, allowing you to expand the available coding area. More on theScripts Panel is explainedabove.

TheEdit menu provides several options for line operations:

../../_images/text_editor_edit_menu.webp
  • Undo*: Allows you to reverse the most recent action or series of actions, restoringdocument or code to its previous state before the changes were made.

  • Redo*: Allows you to reapply an action that was previously undone, effectivelyredoing the last action that was reversed by the Undo function.

  • Cut*: Cuts the selection to the clipboard.

  • Copy*: Copies the selection to the clipboard.

  • Paste*: Pastes the content of the clipboard if it contains text.

  • Select All*: Selects the all code in the text editor.

  • Duplicate Selection: Copies the selection and appends it next to the selection.

  • Duplicate Lines: Duplicates the current line and adds it as a new line below thecurrent line.

  • Evaluate Selection*: Computes the values of the selected text if it containsonlya mathematical expression, such as83*3 orpow(2,3).

  • Toggle Word Wrap: Disables the horizontal scrollbar by wrapping the long lines tothe next line. Note that this is just a visual change and no new linebreaks are added.

  • Line: Provides a set of line operations. Depending on the opened file, the optionsmight also be directly in the Edit menu, instead of a submenu.

    • Move Up: Moves the current line or the selected line(s) one line up.

    • Move Down: Moves the current line or the selected line(s) one line down.

    • Indent*: Indents the text from the caret or the selected line(s), following theindentation setting.

    • Unindent*: Unindents the text from the caret or the selected line(s), following theindentation setting.

    • Delete Line: Deletes the current line or the selected line(s).

    • Toggle Comment*: Comments and uncomments the current line or the selected line(s).You can perform the same action by selecting line(s) and choosing the same actionafter right-clicking on the selected text.

  • Folding: Provides a set of folding options for the selected text. Depending on theopened file, the options might also be directly in the Edit menu, instead of a submenu.

    • Fold/Unfold Line*: If the code in the current line has a code block or code regionbeneath it, it hides this block by collapsing the lines. You can then unfold it usingthis option again, using the ">" arrow next to the line number in the coding area,or clicking on the ellipsis "..." icon at the end of the folded line.

    • Fold All Lines: Folds all code blocks or code regions in the open document.

    • Unfold All Lines: Unfolds all code blocks and code regions in the open document.

    • Create Code Region*: Wraps the selected text in a foldable code region to improvethe readability of larger scripts. SeeBuilt-in types for more.

  • Completion Query: Suggests from built-in or user created symbols to auto-complete thepartially written code.Up andDown arrows navigate up and down, pressingEnter orTab accepts and adds the highlighted symbol to the code.Tab will also replace existing text to the right of the caret.

  • Trim Trailing Whitespaces: Removes extra spacing at the end of each line in the file.

  • Trim Final Newlines: Removes the extra new lines at the end of the file.

  • Indentation: Provides options for the indentation of the open file. Dependingon the opened file, the options might also be directly in the Edit menu, instead of asubmenu.

    • Convert Indent to Spaces: Converts all indentation in the file to spaces.

    • Convert Indent to Tabs: Converts all indentation in the file to tabs.

    • Auto Indent: Converts the indentation of the selected lines (or the entire file) following theindentation setting.

  • Convert Case: Changes the case of the selected text toUpper Case*,Lower Case*, orcapitalizes each initial letter of the words.

  • Syntax Highlighter: Allows you to choose the syntax highlighter.

    • Plain Text: Disables highlighting.

    • Standard: Default highlighting for C# scripts.

    • JSON: Syntax highlighting for JSON files.

    • GDScript: Syntax highlighting for GDScript files.

TheSearch menu provides the following options:

../../_images/text_editor_search_menu.webp
  • Find...: Opens the quick-find bar under the status bar to search for text in the openfile. You can navigate to the next match and previous match using the up and down arrows, respectively. CheckingMatch Case makes the search case-sensitive. CheckingWhole Words means that the text must not have any letters or numbers next to it, only symbols and whitespace.

  • Find Next: Similar to the down arrow, shows the next occurrence.

  • Find Previous: Similar to the up arrow, shows the previous occurrence.

  • Replace...: Opens the find and replace bar under the status bar to find text and replace it in the open file. You can choose to replace them oneat a time or all at once. Additionally, you can limit the replacement to the selectedtext by checking theSelection Only checkbox in the find and replace bar. You can also useCtrl+D toadditionally select the next instance of the currently selected text, allowing you to perform an in-line replacement on multiple occurrences.

  • Find in Files...: Opens a window to search for text within the files in the projectfolder. Selecting "Find..." starts with the chosen folder, and includes the file extensionschecked in the filters. The results are shown in the bottom panel with the number of matchesand total number of files found, in theSearch Results tab. Clicking on a result opensthe file and jumps to the respective line.

  • Replace in Files...: Opens a window to search and replace text with different text within thefound files in the project folder. After clickingReplace..., you can select in which files toreplace using theSearch Results tab in the bottom panel by (un)checking them and usingReplace All button.

../../_images/editor_ui_script_editor_replaceinfiles.webp

Warning

Note that "Replace in Files" operation cannot be undone!

Tip

Both theFind in Files andReplace in Files windows share theSearch...andReplace... buttons. The only difference in the latter window is an additional textfield that automatically fills in the search results panel when theReplace... buttonis clicked. The replacement operation is only executed if you click theReplace Allbutton in this bottom panel, allowing you to also edit the word to replace later withinthis panel.

../../_images/editor_ui_script_editor_replace_all.webp
  • Contextual Help*: Opens the list of built-in class reference similar to pressingF1on a symbol, or choosingLookup Symbol from the context menu.

TheGo To menu lets you navigate within the code at ease with these options:

../../_images/text_editor_goto_menu.webp
  • Go to Function...: Opens the function list to jump to. You can achieve the same resultby typing in the filter methods bar in the script panel.

  • Go to Line...: Jumps to the entered line number in the code editor.

  • Bookmarks: Contains actions for the bookmark functionality, which you can use to findyour way through your code easier, such as an incomplete section. Bookmarked lines willhave a blue bookmark symbol left of the line number.

    • Toggle Bookmark*: Adds or removes the bookmark on the line where the caret is. You canalso right click on a line to achieve this.

    • Remove All Bookmarks: Removes all bookmarks in the open document.

    • Go to Next Bookmark: Jumps to the next bookmark in the open document.

    • Go to Previous Bookmark: Jumps to the previous bookmark in the open document.

    • Bookmarks menu will also contain the list of bookmarked lines, including their linenumber and displaying the partial content in that line.

  • Breakpoints: Breakpoints are helpful while debugging your code. Similar toBookmarksmenu, this menu lets you add or remove breakpoints, navigate between them and directlyjump to a specific breakpoint. An easy way to add a breakpoint is hovering over the blank arealeft of a line number. It will show a faded red circle. Clicking it will add abreakpoint and the circle will stay there. Clicking on a circle removes the breakpoint.

Debug menu offers actions which can be used while debugging. SeeScript editor debug tools and options for more.

Coding area

Note

This section will only cover the basics of the coding area in terms of the userinterface. To learn more about scripting in Godot, refer to theGDScript orScripting documentation.

../../_images/editor_ui_script_editor_coding_area.webp

The coding area is where you will type your scripts if you are using the built-in text editor.It offers highlighting and auto-completion features to help you while you code.

The coding area shows line numbers on the left side. Below the navigation arrows on theright side, there is a clickable minimap that provides an overview of the entire script,allowing you to scroll through it.

If a line of code is long enough (more than 80 characters, by default), the text editorwill display a vertical line that can be used as a soft guideline. For a hard guideline,this value is set to 100 characters, by default. Both values can be changed, or thedisplay of the line can be toggled in the "Appearance" settings of the text editor.

In the script, to the left of function definitions, you might see additional icons. Theoverrideicon indicates that this function is anoverride of an existingfunction. Clicking it opens the documentation of the original function. Thereceiver icon meansthat it is a receiving method of a signal. Clicking it shows where the signal is comingfrom. Afoldable icon to the left of the line denotes a foldable block. You canclick to collapse or expand it.Alternatively, the ellipsis (...) icon can also be clicked to expand a folded block.

The example below summarizes the paragraph above. Lines 52, 56, and 58 are foldable blocks,line 57 is a code region with the name "New Code Region," which you can also fold, and line62 is a folded block.Line 53 is a bookmark, which can quickly be jumped to using theGo To > Bookmarks menu.Line 55 is a breakpoint that can be used indebugging.

../../_images/text_editor_coding_area_indicators.webp

Many of the colors of the text editor such as highlighting colors, or even breakpoint orbookmark icon colors can be customized. You can experiment them by opening the text editorsettings navigating toEditor > Editor Settings > Text Editor section.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.