publish: true
title: Variants in Godot
aliases:
- Variants in Godot
docs: https://docs.godotengine.org/en/stable/classes/class_variant.htmlA Variant:
Containers (Array and Dictionary): Both are implemented using variants. A Dictionary can match any datatype used as key to any other datatype. An Array just holds an array of Variants. Of course, a Variant can also hold a Dictionary and an Array inside, making it even more flexible.
According to the docs, a Variant is "only 20 bytes". Whereas an int is 8 bytes (64 bits). So if you don't statically type your int, then it will take up nearly twice as much space in memory.
var num1 = 0 # variant, 20 bytes
var num2: int = 0 # int, 8 bytes