The variable type is being inferred from a Variant value, so it will be typed as Variant in Godot 4
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.
More on this: Invalid assignment on read-only value (on base: 'Array') in Godot 4
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: Invalid cast: could not convert value to '…' in Godot 4
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
10Run 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.
More on this: How to save and load a game in Godot 4: FileAccess
My Godot 4 project prints this warning: "Parse Error: The variable type is being inferred from a Variant value, so it will be typed as Variant. (Warning treated as error.)". Find where it comes from and fix it. 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"). Then run the game headless and check that Godot's output no longer shows it.Arrays, 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.
More on this: The "export" keyword was removed in Godot 4: every export(...) and its @export annotation
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.
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.
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free