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.

Download for macOSDownload for Windows

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

Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

10

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.

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.