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…

My Notes

00:00 Intro

01:34 Static Typing Vs Variants

02:54 Floats vs Ints

06:48 Boolean

07:14 Strings

07:36 What is a variant

A variant is a type that can dynamically change (e.g. from String to int).

10:11 Colors

10:39 Vectors

13:18 Arrays

15:08 Dictionary

16:32 Packed Arrays

There are various array types in Godot that only work with one specific type:

  • PackedByeArray
  • PackedColorArray
  • PackedStringArray
  • etc.

18:57 Arrays vs PackedArrays

packed 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.

See also: Typed VS Packed array - Archive - Godot Forum

23:37 Long winded explanation of strings and pointers

25:00 StringName

26:14: A StringName is like a String that acts like a singleton

StringName literal syntax

@export var string_name: StringName = &"Hello" 

28:03 NodePath

NodePath literal syntax

@export var node_path: NodePath = ^"Hello" 

30:41 Objects

31:20 RID

32:17 Signals and Callables

36:27 Transformations - Rect2

  • Rect2 simple type representing a rectangle

    • uses float to represent values
    • has two Vector2s representing:
      • origin: x and y of the top left corner
      • size: the width and height of the rect
  • There is also a Rect2i which uses int instead

  • Use case: rects are often used for collision detection.

38:02 Transform2D

40:37 Rect2i and Transform2D demo

41:20 AABB

42:19 Basis

43:35 Transform3D

46:50 Plane

47:26 Projections

48:05 Recap

48:37 Outro

Corrections From the Author

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.

Comments

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.