Game dev
Saved & recent

Assertion

Also called: assert

Related terms: invariant, precondition, logging

A check that a condition you expect to be true really is true. For example, assert(maxHealth > 0) makes an invalid setup visible near its cause, before later code divides by maxHealth.

A failed assertion may stop execution, log an error or break into a debugger, depending on the setup. Some builds disable assertions, so do not put required work inside them or rely on them to validate untrusted input.

Further reading
Godot: @GlobalScope: assert
assert(maxHealth > 0) maxHealth = 100 75 / 100 = 0.75 maxHealth = 0 Assertion failed calculation continues invalid state surfaced
Maximum health of 100 passes the assertion and allows the health fraction to be calculated. Zero fails the assertion before division.

View in the full Game dev collection