A packed array is a list of one built-in type, stored tightly in memory. Godot uses them wherever it handles many values at once, such as the points of a polygon:
[(0.0, 0.0), (100.0, 0.0), (50.0, 80.0), (0.0, 80.0)]
4 points, the second is (100.0, 0.0)
You index, append, loop and check size() the same way as with an Array.
The Packed Array Types
| Type | Each item |
|---|---|
PackedByteArray | a byte, 0 to 255 |
PackedInt32Array, PackedInt64Array | a 32-bit or 64-bit whole number |
PackedFloat32Array, PackedFloat64Array | a 32-bit or 64-bit float |
PackedStringArray | a String |
PackedVector2Array, PackedVector3Array, PackedVector4Array | a vector |
PackedColorArray | a Color |
Where You Meet Them
Many engine properties and methods use packed arrays:
String.split()returns aPackedStringArray.Line2D.points,Polygon2D.polygonandCollisionPolygon2D.polygonarePackedVector2Arrays.- A navigation path from
NavigationServer2D.map_get_path()is aPackedVector2Array. - File and network data is a
PackedByteArray, for exampleFileAccess.get_file_as_bytes().
["fire", "ice", "poison"] true
fire + ice + poison
[72, 105] Hi
Packed Array, Array or Typed Array?
Array | Array[Vector2] | PackedVector2Array | |
|---|---|---|---|
| Item types | any | Vector2 only | Vector2 only |
| Memory | most | most | least |
map(), filter(), pick_random() | yes | yes | no |
sort(), has(), find(), slice() | yes | yes | yes |
| Accepted by engine APIs that want points | converted | converted | directly |
A good rule: use a typed array for game objects and small lists, and a packed array for many plain values or when an engine API asks for one. Convert between them with the constructors:
[30, 10, 20]
[1, 2, 3]
Packed Arrays Are Shared
In Godot 4, a packed array is passed by reference, like an Array. Two variables can point at the same one:
[1, 2, 3, 99]
[1, 2, 3, 99] [1, 2, 3, 99, 4]
The Overflow Trap
Each item has a fixed size, so a value too big for it wraps around without an error:
[44, 5]
[-1294967296]
Use PackedInt64Array for big whole numbers and PackedFloat64Array when 32-bit floats lose too much precision.
Frequently Asked Questions
What is a packed array in Godot?
A packed array stores values of one built-in type side by side in memory, with no per-item overhead. PackedVector2Array holds Vector2 values, PackedStringArray holds strings, and so on. They use less memory than an Array and many engine functions take or return them.
When should I use PackedVector2Array instead of Array[Vector2]?
Use PackedVector2Array for many points, and wherever the engine expects one: Polygon2D.polygon, Line2D.points, Curve2D baked points and navigation paths. Use Array[Vector2] when you want the full set of Array methods such as map() and filter().
Are packed arrays passed by reference in Godot 4?
Yes. Assigning a packed array to another variable or passing it to a function shares it, like an Array. Call duplicate() when you need a separate copy.
Why did my number change in a PackedByteArray?
Each slot is one byte, 0 to 255, so a bigger value wraps around: 300 is stored as 44. PackedInt32Array wraps past about 2.1 billion. Use PackedInt64Array for larger whole numbers.