title: Every Variant in Godot 4
sources: https://www.youtube.com/watch?v=RM_ExxV-0Qo
media_link: https://www.youtube.com/watch?v=RM_ExxV-0Qo
Authors:
- "[[SDG Games]]"
contentPublished:
noteCreated: 2024-11-19
description: In this video, we take a look at every Variant in the Godot game engine. Variants are the foundation for all types in Godot, so starting here will prepare us...
tags:
- clippings
- video
takeaways:
publish: true
Status: âś… ReadIn this video, we take a look at every Variant in the Godot game engine. Variants are the foundation for all types in Godot, so starting here will prepare us...
A variant is a type that can dynamically change (e.g. from String to int).
There are various array types in Godot that only work with one specific type:
PackedByeArrayPackedColorArrayPackedStringArraypacked arrays are less flexible but are more optimized. They take up less space, and are more performant.
Recommendation: Start with a "regular" Array and don't switch to a packed array unless you have a performance problem, or you know in advance that you will deal with very large datasets.
26:14: A StringName is like a String that acts like a singleton
StringName literal syntax
@export var string_name: StringName = &"Hello"
NodePath literal syntax
@export var node_path: NodePath = ^"Hello"
Rect2 simple type representing a rectangle
float to represent valuesVector2s representing:
There is also a Rect2i which uses int instead
Use case: rects are often used for collision detection.
Corrections:
33:30 - I was using the old approach to signals, it's now possible to use signals without strings at all:
signal signal_name
signal_name.connect(function_name)
signal_name.emit()
If you want to send arguments along, you can bind them to the function when connecting or emit them as comma separated list:
signal_name.connect(function_name.bind(23423,"AAAAA"))
signal_name.emit(23423,"AAAAA")
At 09:48, I said "strong typing," but should have said "static typing." Godot is dynamic, with the ability to be static.
16:33 The best way to make a strongly typed Dictionary is to make and export your own class in another Godot script that can then be imported anywhere.