Quick answer: Godot 4 allows one indentation character per script: tabs or spaces, never both. The error means a line starts with a different character than the first indented line of the file, usually because code was pasted from a web page or saved by an external editor. Open the script and choose Edit > Indentation > Convert Indent to Tabs (or Convert Indent to Spaces), then set your editors to the same indent type so it does not come back.
Tabs and spaces look the same on screen, so the line Godot points at appears to be indented correctly. It is a parse error all the same: the script does not load until every line in the file uses one character for indentation. This guide shows the three messages Godot 4 prints and what each one means, how to make the whitespace visible, the menu items that convert a file, the settings that keep the Godot editor and an external editor in agreement, and the other parse errors that are indentation problems under a different name.
- The exact error
- Why GDScript cares
- What causes it
- Make the whitespace visible
- Fix 1: convert the file in the script editor
- Fix 2: set the indent type once
- Fix 3: make external editors and Git agree
- Indentation errors with other names
- How to confirm the fix
- What reaches players
- Related guides
- Frequently asked questions
The exact error
Godot 4 has three messages for this, and you may see more than one at once:
Mixed use of tabs and spaces for indentation.
Used space character for indentation instead of tab as used before in the file.
Used tab character for indentation instead of space as used before in the file.
In the script editor the first error in the file is shown under the code with its position, for example Error at (14, 1): Mixed use of tabs and spaces for indentation. If you run the project, the log has:
SCRIPT ERROR: Parse Error: Used space character for indentation instead of tab as used before in the file.
at: GDScript::reload (res://player.gd:14)
ERROR: Failed to load script "res://player.gd" with error "Parse error".
Godot 3 has a single message with different wording: Mixed tabs and spaces in indentation.
| Message (Godot 4) | What is on the reported line |
|---|---|
Mixed use of tabs and spaces for indentation. | The leading whitespace of this one line contains both a tab and a space, for example a tab followed by two spaces |
Used space character for indentation instead of tab as used before in the file. | This line is indented with spaces, and the first indented line in the file used a tab |
Used tab character for indentation instead of space as used before in the file. | This line is indented with a tab, and the first indented line in the file used spaces |
Why GDScript cares
GDScript has no braces. The depth of the whitespace at the start of a line is what says whether that line belongs to an if, to the function around it, or to the class. A tab has no fixed width, so a line with one tab and a line with four spaces can look aligned in one editor and misaligned in another. If the parser guessed, the same file could mean two different programs. Godot 4 refuses to guess: the first indented line of code decides the character for the whole file, and every later line is held to it.
A few kinds of line are exempt, which explains why some odd-looking files still load:
- Blank lines and lines that contain only a comment are skipped.
- Lines inside an open
(,[or{are not checked, so arguments or dictionary entries spread over several lines can be aligned however you like. - A line that continues the previous one after a trailing
\is not checked.
Godot 3 was more lenient. It compared each line only with the blocks enclosing it, so one function could be indented with tabs and the next with spaces. Godot 4 applies the rule to the whole file, which is why a script that loaded in Godot 3 can report Used space character for indentation after the project is converted.
What causes it
- Pasted code. Snippets from documentation pages, forum posts, chat tools and AI assistants are almost always indented with spaces, often two or four per level. The Godot editor indents with tabs by default. Paste three space-indented lines into a tab-indented function and the first pasted line gets the error.
- An external editor with different settings. VS Code, Vim and others insert spaces when you press
Tabunless told otherwise, and some detect the indent style per file and get it wrong on a short file. - The file started with spaces. A script that came from a template, a generator or another developer uses spaces from line 2 on. You open it in Godot, add a function, and Godot blames your new tab-indented lines with
Used tab character, because the file’s first indented line used spaces. - A stray space next to a tab. A space typed at the start of an indented line, or spaces added after the tabs to line something up, produces
Mixed use of tabs and spaceson that single line. - A merge. Two branches indented the same file differently, and the merged result has both.
Make the whitespace visible
- Go to the line in the message. It is the first line that disagrees with the start of the file, which is not always the line that is wrong. When the file began with spaces and you typed tabs later, the message points at your new code and the older lines are the ones to convert.
- Open Editor > Editor Settings > Text Editor > Appearance > Whitespace. Draw Tabs is on by default. Turn on Draw Spaces as well. Each tab is now drawn as a small arrow and each space as a dot, so a space-indented block stands out from the tab-indented lines around it.
- Check the first indented line of the script, typically the first line inside the first function or the first line under
class,enumor a multi-line declaration. That line sets the character every other line is compared with. - For a single
Mixed useline, put the caret at the start of the line and step through the whitespace with the arrow keys. A tab moves the caret a whole indent in one step, a space moves it one column.
Fix 1: convert the file in the script editor
With the script open, use the Edit menu above the code:
- Edit > Indentation > Convert Indent to Tabs (
Ctrl+Shift+I,Cmd+Shift+Ion macOS) - Edit > Indentation > Convert Indent to Spaces (
Ctrl+Shift+Y)
Both work on the whole file and only touch the whitespace at the start of each line. Lines inside a multi-line string are left alone.
There is one catch with widths. Convert Indent to Tabs replaces each run of Size leading spaces with one tab, where Size is the editor’s indent size (4 by default). Code indented with 2 spaces per level does not convert cleanly at size 4: a 2-space line is left as it is, and a 6-space line becomes a tab followed by 2 spaces, which is a Mixed use line. For a 2-space snippet:
- Open Editor > Editor Settings > Text Editor > Behavior > Indent and set Size to 2.
- Run Convert Indent to Tabs on the script.
- Set Size back to 4. Tabs are single characters, so the file is unaffected by the change.
Here is what the conversion does to a pasted block, with → standing for a tab and · for a space:
# Before: the function uses tabs, the pasted lines use four spaces
func take_damage(amount: int) -> void:
→health -= amount
····if health <= 0:
········die()
# After Convert Indent to Tabs
func take_damage(amount: int) -> void:
→health -= amount
→if health <= 0:
→→die()
Edit > Indentation > Auto Indent (Ctrl+I) is a different tool. It rebuilds the indentation of the selected lines, or of the whole file when nothing is selected, from the number of whitespace characters each line starts with. That makes it useful for a file that is consistently indented with spaces of any width, where each level becomes one indent of your configured type. On a file that already mixes the two it can change the nesting, because one tab and four spaces count as different depths. Use the convert items for mixed files.
Fix 2: set the indent type once
The settings that control what the Godot script editor types and saves are under Editor > Editor Settings > Text Editor > Behavior:
| Setting | Default | What it does |
|---|---|---|
| Indent > Type | Tabs | The character the Tab key and automatic indentation insert |
| Indent > Size | 4 | How wide a tab is drawn, how many spaces one level is in spaces mode, and the run length the convert commands use |
| Indent > Auto Indent | On | Starts a new line at the depth of the previous one |
| Files > Convert Indent on Save | On | Converts leading indentation to the chosen Type every time the script is saved from the Godot editor |
Convert Indent on Save is why this error often vanishes when you press Ctrl+S in the Godot editor. It follows the same run-of-Size rule as the menu command, so it does not rescue 2-space code at size 4, and it never runs for a file saved by another program.
Tabs or spaces is your choice, as long as each file sticks to one. The official GDScript style guide uses tabs, and the editor’s defaults follow it, so tabs cause the least friction when you copy code between Godot projects.
Fix 3: make external editors and Git agree
VS Code
Add a language-specific block to settings.json so GDScript files always get tabs, whatever your default for other languages is:
{
"[gdscript]": {
"editor.insertSpaces": false,
"editor.tabSize": 4,
"editor.detectIndentation": false
},
"editor.renderWhitespace": "boundary"
}
To repair a file from inside VS Code, open the Command Palette and run Convert Indentation to Tabs. The rest of the editor setup is in the VS Code guide for Godot.
.editorconfig
An .editorconfig file at the project root tells every editor that supports the format which indent style to use (VS Code needs the EditorConfig extension, JetBrains IDEs read it without one). Projects created with Godot 4.4 or later already contain one that sets the charset. Add a section for scripts:
root = true
[*]
charset = utf-8
[*.gd]
indent_style = tab
indent_size = 4
Git
Git can flag space indentation before it is committed. Put this in .gitattributes:
*.gd whitespace=indent-with-non-tab,tabwidth=4
Then git diff --check (or git diff --cached --check for staged changes) prints lines such as player.gd:14: indent with spaces. for any changed line whose indentation contains four or more spaces in a row. A project that standardizes on spaces uses whitespace=tab-in-indent instead. This only reports; the conversion is still done in an editor.
Indentation errors with other names
Mixed indentation often arrives with a second error, and sometimes the second one is the only one shown. When Godot measures depth it counts a tab as one indent Size of columns, so a line with one tab and a line with three spaces sit at different depths even though neither is “mixed”.
| Message (Godot 4) | Usual cause |
|---|---|
Expected indented block after "if" block. or Expected indented block after function declaration. | The line after a : is not deeper than the line with the colon, or the block is empty and needs pass |
Unindent doesn't match the previous indentation level. | A line steps back to a depth that no enclosing block uses, such as 3 spaces under a 4-space block |
Unexpected "Indent" in class body. | A line at the top level of the script is indented, typically a pasted func or var that kept the indentation it had where it was copied from |
Godot 3 words the middle one as Unindent does not match any outer indentation level. The first family has its own walkthrough in the “Expected indented block” guide. If you see one of these on a line that looks right, turn on Draw Spaces before changing any code.
How to confirm the fix
Save the script and check that the error line under the code is gone. With Draw Spaces on, scroll through the file once: no dots should remain at the start of any line in a tab-indented file, apart from lines inside brackets. If the project is in Git, run git diff -w on the file. The -w flag ignores whitespace, so empty output proves the conversion changed nothing else.
Then look for other files with the same problem, because every script is checked separately when it is first loaded. In a project that uses tabs, this lists each .gd file that has a line starting with a space:
grep -rlE '^ +[^ ]' --include='*.gd' .
Lines aligned with spaces inside brackets will show up as false positives. To let Godot itself judge a file without opening the editor, run it from the project folder with --check-only, which parses the script and exits with a failure code on any error:
godot --headless --path . --check-only --script res://player.gd
What reaches players
This error belongs to the editor, and Bugnet has no part in finding or fixing it. The only way it leaves your machine is inside a script that nobody loaded before the build went out: a file touched in an external editor on release day, a rarely opened menu, a script in a mod or downloadable pack. On the player’s machine that script fails to load, the parse error is written to the engine’s log, and the node it was attached to does nothing.
Bugnet’s Godot SDK reads that log file for its automatic error capture. With File Logging enabled (it is off by default on mobile exports), the failure can arrive as a report with the message, the script path, platform, OS and game version, and repeats stack into one entry with an occurrence count. It cannot report anything that happens before the engine starts logging, and it does not replace the cheap check: run --check-only over your scripts, or load every scene once, before you export. The SDK setup is in the SDK docs.
Related guides
- How to Fix “Expected indented block” Parse Errors in GDScript
- How to Set Up VS Code for Godot and GDScript
- How to Fix “Parser Error: Identifier not found” in Godot
- How to Capture Script Errors at Runtime in an Exported Godot 4 Game
- How to Fix “IndentationError: unexpected indent” and Friends in Python Game Code
Frequently asked questions
What does Mixed use of tabs and spaces for indentation mean in Godot?
The whitespace at the start of one line contains both a tab and a space. GDScript uses indentation as syntax and Godot 4 accepts only one indentation character per script, so the file does not load until the line is fixed. Convert the file with Edit > Indentation > Convert Indent to Tabs in the script editor.
How do I convert spaces to tabs in the Godot script editor?
Open the script and choose Edit > Indentation > Convert Indent to Tabs, or press Ctrl+Shift+I. It replaces each run of leading spaces equal to the editor indent size, 4 by default, with one tab. For code indented with 2 spaces, set the indent size to 2 in the Editor Settings first, convert, then set it back.
Why do I get this error after pasting code into Godot?
Code copied from web pages, forums and chat tools is almost always indented with spaces, while the Godot editor uses tabs by default. The pasted lines then use a different character than the rest of the file. Convert the indentation after pasting, or save the script in the Godot editor with Convert Indent on Save enabled.
Should I use tabs or spaces in GDScript?
Either works as long as every line in a file uses the same one. The official GDScript style guide and the default editor settings use tabs, so tabs cause the least friction. Set the same choice in the Godot Editor Settings and in any external editor you use.
Why does Godot say Used tab character for indentation instead of space on a line I just typed?
The first indented line of the file decides the character for the whole script, and in this file that line used spaces. Your new line is indented with a tab, so Godot reports it even though the older lines are the unusual ones. Convert the whole file to tabs and the message goes away.
The first indented line of a script decides whether the file uses tabs or spaces. Turn on Draw Spaces to see which lines disagree, then convert the whole file from Edit > Indentation.