Material Box

Material Box

WEB Design & Material Images

Godot - Set array size

Godot

GDScript code example to set array size.


Can set array size using resize() in GDScript.
Added values will be set to "null".
Also resolves errors like "Invalid set index '0' (on base: 'Array')" when adding value to empty array.

var array = []
array.resize(5)

print(array)
# [<null>, <null>, <null>, <null>, <null>]

If resize() is set to lower number than values that already exist in array, values are truncated from beginning of array.

var array = ["apple", "lemon", "apple", "banana"]
array.resize(2)

print(array)
# ["apple", "lemon"]

Godot

TitleGodot - Set array size

CategoryGodot

Created

Update

AuthorYousuke.U