Assertion failed in Godot 4
An assert() in your code was given a false condition. assert(hp > 0, "hp must be positive") with hp = 0 stops with Assertion failed: hp must be positive. The assert is doing its job: find why the condition is false at that point, here an hp that was never set above 0.
AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.
Intel or AMD Chromebook, with Linux turned on.
What Godot is checking
assert(condition, message) checks the condition in debug builds. When it is false the VM stops the function with Assertion failed, followed by the message if one was given, and the debugger breaks there in the editor.
Asserts are compiled out of release exports: the condition is not even evaluated. Never put code with a side effect, such as a function that changes state, inside an assert.
Reproduce it
An assert that hp is positive, with hp still 0.
extends Node
var hp := 0
func _ready() -> void:
assert(hp > 0, "hp must be positive")
print("after")
What Godot 4.7.2 prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
SCRIPT ERROR: Assertion failed: hp must be positive
at: _ready (res://answers/assertion-failed/repro.gd:6)
GDScript backtrace (most recent call first):
[0] _ready (res://answers/assertion-failed/repro.gd:6)Fix it
Give hp its starting value before the code that relies on it.
extends Node
var hp := 0
func _ready() -> void:
hp = 100
assert(hp > 0, "hp must be positive")
print("hp ", hp)
What the fixed script prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
hp 100Run this fix with your agent
Flockbay is the Godot editor with an AI agent built in. Paste this into Flockbay's chat, or into Claude Code or Codex connected to Flockbay over MCP: the agent finds the cause in your project, applies the fix, runs the game headless and reads Godot's output to check it.
My Godot 4 project prints this error: "Assertion failed: hp must be positive". Find where it comes from and fix it. An assert() in your code was given a false condition. assert(hp > 0, "hp must be positive") with hp = 0 stops with Assertion failed: hp must be positive. The assert is doing its job: find why the condition is false at that point, here an hp that was never set above 0. Then run the game headless and check that Godot's output no longer shows it.Verified on Godot 4.7.2
Both scripts on this page were run headless on Godot 4.7.2 (4.7.2.stable.mono.official.ed1daf0bf) on 18 October 2026, and the output above is what Godot printed, unedited.
Where the check lives in Godot's source: gdscript_vm.cpp line 3895, the message with your text, assert in the @GDScript class reference.
Questions
- Does assert() run in an exported game?
- Not in a release export. Asserts run in the editor and in debug exports only.
- What does Assertion failed. without text mean?
- The same check, from an assert() given no message. Add a message as the second argument so the error says what was expected.
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free