Skip to content

Underlying Data Structures

The gdextension interface to the engine supports a fixed set of underlying data types, all of them have an equivalent convenience type in Go and a high-performance type (this type is allocation efficient and suitable for use in hot functions).

All of the data types have a package underneath graphics.gd/variant. With the exception of Object, all these packages are implemented in pure Go to avoid any coupling or overhead when making calls to the engine. You can import these packages in any Go project.

Engine TypeConvenience TypeHigh Performance Type
Variantanyvariant.Any
boolboolbool
intintint64
floatFloat.Xfloat64
StringstringString.Readable
Vector2Vector2.XYVector2.XY
Vector2iVector2i.XYVector2i.XY
Rect2Rect2.PositionSizeRect2.PositionSize
Rect2iRect2i.PositionSizeRect2i.PositionSize
Vector3Vector3.XYZVector3.XYZ
Vector3iVector3i.XYZVector3i.XYZ
Transform2DTransform2D.OriginXYTransform2D.OriginXY
Vector4Vector4.XYZWVector4.XYZW
Vector4iVector4i.XYZWVector4i.XYZW
PlanePlane.NormalDPlane.NormalD
QuaternionQuaternion.IJKLQuaternion.IJKL
AABBAABB.PositionSizeAABB.PositionSize
BasisBasis.XYZBasis.XYZ
Transform3DTransform3D.BasisOriginTransform3D.BasisOrigin
ProjectionProjection.XYZWProjection.XYZW
ColorColor.RGBAColor.RGBA
StringNamestringString.Name
NodePathstringPath.ToNode
Signalchan TSignal.Any
RIDRID.TRID.Any
Object*T | T.InstanceT.Advanced
Callablefunc(...T) (...T)Callable.Function
Dictionarystruct | map[T]TDictionary.Any
Array[]TArray.Any
PackedByteArray[]bytePacked.Bytes
PackedInt32Array[]int32Packed.Array[int32]
PackedInt64Array[]int64Packed.Array[int64]
PackedFloat32Array[]float32Packed.Array[float32]
PackedFloat64Array[]float64Packed.Array[float64]
PackedStringArray[]stringPacked.Strings
PackedVector2Array[]Vector2.XYPacked.Array[Vector2.XY]
PackedVector3Array[]Vector3.XYZPacked.Array[Vector3.XYZ]
PackedColorArray[]Color.RGBAPacked.Array[Color.RGBA]
PackedVector4Array[]Vector4.XYZWPacked.Array[Vector4.XYZW]

graphics.gd defines some additional variant types to improve type-safety and readability.

Additional TypeUnderlying Engine Type
Enum.Int[T]int
Angle.Radiansfloat
Angle.Degreesfloat
Error.Codeint
Euler.RadiansVector3
Euler.DegreesVector3
Path.ToFileString
Path.ToResourceString
Path.ToDirectoryString

The functions available within the Vector2, Vector2i, Vector3, Vector3i, Vector4, and Vector4i packages can operate with any matching vector types (as long as they share the same underlying struct), they are not requred by graphics.gd and you are more than welcome to define your own vector types with their own set of methods .

package myvectors
type MyVector2 struct {
X float32
Y float32
}
func (v MyVector2) Add(other MyVector2) MyVector2 {
return Vector2.Add(v, other) // this works without any special type conversions.
}

In this example, MyVector2 can be passed to engine methods as if it were a Vector2.XY.