Variants Tagged union - Wikipedia are data that boxes in other data. Very important concept in lower-level languages. They contain the data and information about the type of the data. E.g. you could check if a Variant is a float or int and react accordingly. In GDScript if you do not assign a type to a variable it is Variant by default which is a tagged union/variant/sum type of all the basic types GDscript supports. If you have a look at variant.h this should be a list of the types it can box in:
class Variant {
public:
// If this changes the table in variant_op must be updated
enum Type {
NIL,
// atomic types
BOOL,
INT,
FLOAT,
STRING,
// math types
VECTOR2,
VECTOR2I,
RECT2,
RECT2I,
VECTOR3,
VECTOR3I,
TRANSFORM2D,
VECTOR4,
VECTOR4I,
PLANE,
QUATERNION,
AABB,
BASIS,
TRANSFORM3D,
PROJECTION,
// misc types
COLOR,
STRING_NAME,
NODE_PATH,
RID,
OBJECT,
CALLABLE,
SIGNAL,
DICTIONARY,
ARRAY,
// typed arrays
PACKED_BYTE_ARRAY,
PACKED_INT32_ARRAY,
PACKED_INT64_ARRAY,
PACKED_FLOAT32_ARRAY,
PACKED_FLOAT64_ARRAY,
PACKED_STRING_ARRAY,
PACKED_VECTOR2_ARRAY,
PACKED_VECTOR3_ARRAY,
PACKED_COLOR_ARRAY,
PACKED_VECTOR4_ARRAY,
VARIANT_MAX
};
Dictionary keys need to be of type Variant to support different types of keys (floats, strings and so on). In lower-level languages you can either have your dictionary just accept one kind of key/value or use a Variant type.
There is a global hash function in GDscript. print(hash(get_node("AnimatedSprite2D")))
Nodes should be hashable as far as I can tell. There is also a hash()-function in variant.cpp that handles various cases, Node inherits from Object so I guess the gdscript function ends up at:
case OBJECT: {
return hash_one_uint64(hash_make_uint64_t(_get_obj().obj));