The variable type is being inferred from a Variant value, so it will be typed as Variant in Godot 4
By Eduardo Orellana · Updated
var hp := data.get("hp") asks GDScript to infer a type from a value whose type is Variant, which says nothing. The INFERENCE_ON_VARIANT warning is an error by default, so the script fails to parse with The variable type is being inferred from a Variant value, so it will be typed as Variant. (Warning treated as error.). Write the type yourself, var hp: int = data.get("hp", 0), or drop the colon, var hp = data.get("hp").
AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.
Intel or AMD Chromebook, with Linux turned on.
What Godot is checking
:= means "give this variable the type of its value". Dictionary.get() and Array element reads return Variant, which can hold anything, so there is no type to infer. GDScript reports this as the INFERENCE_ON_VARIANT warning.
That warning's default level in Project Settings is Error, under Debug, GDScript, so the script does not load. The same setting can lower it to a warning, but naming the type is the real fix.
Reproduce it
A typed-inference declaration from a Dictionary.get() call.
extends Node
var data := {"hp": 10}
func _ready() -> void:
var hp := data.get("hp")
print(hp)
What Godot 4.7.2 prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
SCRIPT ERROR: Parse Error: The variable type is being inferred from a Variant value, so it will be typed as Variant. (Warning treated as error.)
at: GDScript::reload (res://answers/the-variable-type-is-being-inferred-from-a-variant-value/repro.gd:6)
ERROR: Failed to load script "res://answers/the-variable-type-is-being-inferred-from-a-variant-value/repro.gd" with error "Parse error".
at: load (modules/gdscript/gdscript_resource_format.cpp:46)Fix it
Name the type, and give get() a default of that type.
extends Node
var data := {"hp": 10}
func _ready() -> void:
var hp: int = data.get("hp", 0)
print(hp)
What the fixed script prints
More on this: The "export" keyword was removed in Godot 4: every export(...) and its @export annotation
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
10Arrays, get_node() and JSON
Reading an untyped array, var first := items[0], calling get_node() without a cast, and JSON.parse_string() all give Variant. Type the array (Array[String]), cast the node (get_node("Player") as Player), or write the type.
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_warning.cpp line 165, the INFERENCE_ON_VARIANT text](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_warning.cpp#L165).
Questions
- Can I turn this error off?
- Yes: Project Settings, Debug, GDScript, Inference On Variant. Lowering it hides the warning; the variable is still Variant.
- Is var x = value (without the colon) slower?
- Untyped variables skip the type checks and some typed instructions. For most game code the difference is small; types catch mistakes earlier.
Related
- Cannot infer the type of "…" variable because the value is "null"
- Invalid access to property or key on type 'Dictionary'
- Every verified Godot 4 answer
- Invalid cast: could not convert value to '…' in Godot 4
- Trying to return a value of type "…" from a function whose return type is "…" in Godot 4
- Trying to assign a non-object value to a variable of type '…' in Godot 4
- Trying to assign value of type 'String' to a variable of type 'int' in Godot 4
- Trying to assign an array of type "Array" to a variable of type "Array[…]" in Godot 4
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free