Quick answer: On Godot 4.5 and later, extend Logger, override _log_error(), and register it with OS.add_logger() in an autoload’s _init(). Queue each error under a Mutex and send it from _process() with an HTTPRequest node. On Godot 4.0 to 4.4 there is no callback, so tail user://logs/godot.log for new ERROR: and SCRIPT ERROR: lines. Either way you receive what the engine prints, and a release export prints less than a debug one.
In the editor a script error stops the game and opens the debugger on the offending line. In an exported build nothing stops. The function that hit the error is abandoned, the engine writes a line to a log file the player will never open, and the game carries on with a variable that was never set or a signal that was never connected. The player reports that “the shop is broken” and you have nothing to go on. This guide shows how to capture script errors at runtime in an exported Godot 4 game and get them off the player’s machine, on 4.5 with the new logger API and on older 4.x versions without it.
- Why an exported Godot game fails silently
- Godot 4.5 and later: a custom Logger with OS.add_logger
- A complete error reporter autoload
- Getting GDScript backtraces in release builds
- Godot 4.0 to 4.4: tail godot.log for ERROR lines
- Engine crashes: read the previous run’s log
- Throttle, dedupe and stable titles
- What the Bugnet Godot SDK captures for you
- Related guides
- Frequently asked questions
Why an exported Godot game fails silently
What happens when GDScript goes wrong depends on which export template the build uses.
- Debug export (the Export With Debug box ticked). The virtual machine checks every call and property access. When one fails it stops the current function, prints a
SCRIPT ERROR:line with the script path and line number, and returns to the engine. The next frame runs as if nothing happened. - Release export. Most of those runtime checks are compiled out for speed. Calling a method on a freed node or reading a property from
nullmay log nothing at all. Execution continues past the bad line with an empty value, and in the worst case the engine crashes a moment later somewhere unrelated.assert()is also skipped in release builds.
In both cases the player keeps playing a game that is now in a state you never tested. That is why capturing these matters more in Godot than in engines where a script exception is loud.
What a release export still reports is everything that goes through the engine’s own error handling: your push_error() calls, a get_node() that finds nothing, a resource that fails to load, an index out of bounds in a built-in container, a failed signal connection. That is a large share of real bugs, and it is the stream the techniques below listen to. If you want the VM-level script errors from players too, ship your playtest and beta builds as debug exports.
Godot 4.5 and later: a custom Logger with OS.add_logger
Godot 4.5 added the Logger class. You extend it, override one or both of its virtual methods, and hand an instance to OS.add_logger(). From then on the engine calls your object for everything it would print.
func _log_error(function: String, file: String, line: int, code: String,
rationale: String, editor_notify: bool, error_type: int,
script_backtraces: Array[ScriptBacktrace]) -> void
func _log_message(message: String, error: bool) -> void
_log_error() receives errors and warnings. _log_message() receives ordinary output from print() and printerr(), with error set for the latter. The parameters of _log_error() are:
| Parameter | Meaning |
|---|---|
function, file, line | Where the error was raised. For a script error this is the GDScript function and res:// path. For an engine error or push_error() it is the C++ source location. |
code | The error text, or the condition that failed. |
rationale | The human-readable explanation when the engine supplies one. Often empty, in which case code is the message. |
error_type | ERROR_TYPE_ERROR (0), ERROR_TYPE_WARNING (1), ERROR_TYPE_SCRIPT (2) or ERROR_TYPE_SHADER (3). |
script_backtraces | The GDScript call stacks that led here, one ScriptBacktrace per script language. |
Three rules come with the API, and each one causes a hard-to-find bug if you ignore it.
- Both methods can be called from any thread, and from several at once. Errors raised on the rendering thread, in a
WorkerThreadPooltask or during threaded loading arrive on that thread. Guard everything the logger touches with aMutex, and do not touch the scene tree from inside it. - Do not log from inside the logger. Calling
push_error()orpush_warning()in_log_error(), orprint()in_log_message(), is not supported and can recurse. - Register early. An autoload’s
_init()runs before any scene’s_ready(). Put the autoload first in the list so it also sees errors from your other autoloads.
A complete error reporter autoload
Save this as error_reporter.gd and add it under Project Settings > Globals > Autoload. The logger only collects. The node drains the queue on the main thread and posts each distinct error once. The endpoint and field names are Bugnet’s public submit API, and any HTTP endpoint of your own works the same way.
extends Node
const URL := "https://api.bugnet.io/api/bugs/submit"
const API_KEY := "sk_live_your_project_key"
const MAX_REPORTS := 20
class Catcher extends Logger:
var _mutex := Mutex.new()
var _pending: Array[Dictionary] = []
var _recent := PackedStringArray()
func _log_error(function: String, file: String, line: int, code: String,
rationale: String, _editor_notify: bool, error_type: int,
script_backtraces: Array[ScriptBacktrace]) -> void:
if error_type == ERROR_TYPE_WARNING:
return
var trace := ""
for backtrace in script_backtraces:
trace += backtrace.format() + "\n"
_mutex.lock()
_pending.append({
"message": rationale if rationale != "" else code,
"where": "%s (%s:%d)" % [function, file.get_file(), line],
"trace": trace,
"script": error_type == ERROR_TYPE_SCRIPT,
"recent": "\n".join(_recent),
})
_mutex.unlock()
func _log_message(message: String, _error: bool) -> void:
_mutex.lock()
_recent.append(message.strip_edges())
if _recent.size() > 50:
_recent.remove_at(0)
_mutex.unlock()
func take() -> Array[Dictionary]:
_mutex.lock()
var out := _pending
_pending = []
_mutex.unlock()
return out
var _catcher := Catcher.new()
var _seen := {}
func _init() -> void:
OS.add_logger(_catcher)
func _ready() -> void:
process_mode = Node.PROCESS_MODE_ALWAYS
func _process(_delta: float) -> void:
for err in _catcher.take():
_report(err)
func _report(err: Dictionary) -> void:
var title: String = err.message
if err.where != "":
title = "%s at %s" % [err.message, err.where]
title = title.left(200)
if _seen.has(title) or _seen.size() >= MAX_REPORTS:
return
_seen[title] = true
var payload := {
"title": title,
"description": "%s\n\nat: %s\n\n%s\n--- Recent output ---\n%s" % [
err.message, err.where, err.trace, err.recent],
"category": "crash" if err.script else "other",
"priority": "high",
"platform": OS.get_name(),
"game_version": str(ProjectSettings.get_setting("application/config/version", "")),
"os_info": "%s %s" % [OS.get_distribution_name(), OS.get_version()],
"device_info": "%s, %s" % [OS.get_processor_name(),
RenderingServer.get_video_adapter_name()],
"auto_captured": true,
}
var http := HTTPRequest.new()
add_child(http)
http.request_completed.connect(
func(_result, _code, _headers, _body): http.queue_free())
http.request(URL, ["Content-Type: application/json", "X-API-Key: " + API_KEY],
HTTPClient.METHOD_POST, JSON.stringify(payload))
A few details are doing real work here. take() swaps the array out under the lock, so the logger is never blocked while the main thread sends. PROCESS_MODE_ALWAYS keeps reports flowing while the tree is paused, which is when a player is most likely to quit. The last 50 lines of normal output travel with each error, so you can see what the game was doing before it went wrong. And nothing in the send path prints, because a failed request that logged an error would feed itself back into the logger.
Getting GDScript backtraces in release builds
For a script error, function, file and line already point at your code. For push_error() and engine errors they point at C++ source, which tells you nothing about which of your scripts made the call. The answer is in script_backtraces, and by default those only contain frames in the editor and in debug builds.
To keep them in release exports, enable Project Settings > Debug > Settings > GDScript > Always Track Call Stacks (debug/settings/gdscript/always_track_call_stacks). There is a small runtime cost for tracking the stack, and for most games a named function and line on every production error is worth it. The backtraces passed to the logger do not include variable values. If you need locals as well, call Engine.capture_script_backtraces() yourself inside the logger.
Godot 4.0 to 4.4: tail godot.log for ERROR lines
Before 4.5 there is no hook into the error stream, but the engine writes the same text to a file. The default path is user://logs/godot.log (the debug/file_logging/log_path setting). File logging is controlled by Project Settings > Debug > File Logging > Enable File Logging. It is normally on for desktop platforms and off elsewhere, so check it for each platform you ship. Web exports have no log file to read, which is one more reason to move to the logger when you can.
Each error is two lines: the message, then the location.
ERROR: Node not found: "HUD/Coins" (relative to "/root/Main").
at: get_node (scene/main/node.cpp:1792)
SCRIPT ERROR: Invalid access to property or key 'hp' on a base object of type 'Nil'.
at: _physics_process (res://player.gd:42)
Reading the whole file every second gets slower as the log grows. Remember how far you have read and only read what was appended. Replace the Catcher parts of the autoload above with this:
const PREFIXES := ["ERROR:", "SCRIPT ERROR:", "USER ERROR:", "USER SCRIPT ERROR:"]
var _log_path := ""
var _offset := 0
var _since_check := 0.0
func _ready() -> void:
process_mode = Node.PROCESS_MODE_ALWAYS
_log_path = str(ProjectSettings.get_setting(
"debug/file_logging/log_path", "user://logs/godot.log"))
func _process(delta: float) -> void:
_since_check += delta
if _since_check < 1.0:
return
_since_check = 0.0
var file := FileAccess.open(_log_path, FileAccess.READ)
if file == null:
return
var length := file.get_length()
if length < _offset:
_offset = 0 # the log was rotated or truncated
file.seek(_offset)
var chunk := file.get_buffer(length - _offset)
var last_newline := chunk.rfind(10)
if last_newline < 0:
return # only part of a line so far, wait for the rest
_offset += last_newline + 1
var lines := chunk.slice(0, last_newline).get_string_from_utf8().split("\n")
for i in lines.size():
var line := lines[i].strip_edges()
var is_error := false
for prefix in PREFIXES:
if line.begins_with(prefix):
is_error = true
if not is_error:
continue
var where := ""
if i + 1 < lines.size():
where = lines[i + 1].strip_edges().trim_prefix("at: ")
_report({"message": line, "where": where, "trace": "",
"script": line.contains("SCRIPT ERROR:"), "recent": ""})
Only complete lines are consumed, so a message that is half written when you look is picked up on the next pass. The offset is counted in bytes, which keeps it correct when the log contains non-ASCII text. Because the file starts fresh on each launch, the first pass also catches errors printed before your autoload existed.
Engine crashes: read the previous run’s log
A segmentation fault inside the engine or a driver is a different event. No script runs after it. When the engine’s crash handler is active it writes a backtrace into the same log file as the process dies, but your game cannot see that in the session that crashed.
It can see it in the next one. At startup Godot renames the previous godot.log to a timestamped file in the same folder and keeps up to five of them (debug/file_logging/max_log_files). Check the newest one when your autoload starts:
func _check_previous_run() -> void:
var dir := DirAccess.open("user://logs")
if dir == null:
return
var old_logs: Array[String] = []
for file_name in dir.get_files():
if file_name.begins_with("godot") and file_name.ends_with(".log") \
and file_name != "godot.log":
old_logs.append(file_name)
if old_logs.is_empty():
return
old_logs.sort()
var text := FileAccess.get_file_as_string("user://logs/" + old_logs[-1])
var at := text.find("Program crashed")
if at < 0:
return
_report({"message": "Engine crash in previous session", "where": "",
"trace": text.substr(at, 4000), "script": false,
"recent": text.substr(maxi(0, at - 2000), 2000)})
Call it from _ready(). Official release templates ship without debug symbols, so the backtrace is mostly addresses, but you learn that the crash happened, how often, on which GPU and in which version, and the lines before it show what the game was doing.
Throttle, dedupe and stable titles
An error inside _process() repeats every frame. Three guards keep one bug from turning into thousands of requests.
- Send each distinct error once per session. The
_seendictionary above does this. The occurrence count you care about is how many players hit it, not how many frames. - Cap the total. Twenty reports a session is plenty. A build that produces more than that has one underlying problem, and the first few reports already describe it.
- Make the title stable. Message plus location is a good key because it is identical on every machine. Keep node paths with instance numbers, timestamps and player names out of your
push_error()text, or put them after the first sentence, otherwise every occurrence looks like a new bug.
Write your push_error() calls with this in mind. push_error("Save failed: slot file unreadable") groups. push_error("Save failed for %s at %s" % [player_name, Time.get_datetime_string_from_system()]) never will.
What the Bugnet Godot SDK captures for you
The Bugnet Godot SDK is a single GDScript autoload that uses the log-file approach, so it works on every Godot 4.x version. Once a second it reads the bytes appended to user://logs/godot.log since its last check, up to the last complete line, keeps recent lines as context, and files any line containing ERROR:, SCRIPT ERROR: or FATAL: as a report with the surrounding lines attached. It skips its own output so a failed report can never report itself. Because it reads the log file, file logging has to be enabled for the platform.
Reports arrive in a dashboard with the OS, device and game version, a screenshot when screenshot capture is on, and an occurrence count when the same title repeats. Players can also send their own reports through the in-game widget from the same autoload. The free plan covers one project and up to 100 bug reports in total. If you prefer the reporter from this article, it already posts to the same submit endpoint, and the SDK docs cover both routes.
Related guides
- Where Are Godot Crash Logs? Finding godot.log on Windows, macOS, Linux and Steam Deck
- How to Debug GDScript Errors in Godot
- How to Fix a Godot Exported Game That Closes Instantly With No Error
- How to Fix “Attempt to call function on a null instance” in Godot
- How to Add In-Game Bug Reporting to Your Godot Project
Frequently asked questions
How do I catch errors at runtime in Godot 4?
From Godot 4.5, extend the Logger class, override _log_error, and register an instance with OS.add_logger in an autoload. The engine then calls your method for every error it prints. On Godot 4.0 to 4.4 there is no callback, so read new lines from user://logs/godot.log while the game runs.
Does a GDScript error crash an exported Godot game?
Usually not. In a debug export the failing function stops, the engine prints a SCRIPT ERROR line, and the game carries on with the next frame. In a release export most of GDScript’s runtime checks are compiled out, so the same mistake may log nothing and leave the game in a broken state.
Is there a callback for push_error in Godot?
Not a signal, but a custom Logger registered with OS.add_logger receives every push_error and push_warning call through _log_error, along with engine errors. This needs Godot 4.5 or later.
Why are GDScript backtraces empty in my release export?
Script call stacks are only tracked in the editor and in debug builds by default. Turn on Debug, Settings, GDScript, Always Track Call Stacks in Project Settings to keep them in release exports.
Where is the Godot log file in an exported game?
By default at user://logs/godot.log, with up to five older runs kept beside it under timestamped names. File logging is a project setting under Debug, File Logging, and it needs to be enabled for the platform you export to.
An exported Godot game does not stop on a script error, so the only way to hear about one is to listen to the error stream yourself and send what you hear.