Godot - Make Array Immutable
GDScript code example to make an array read-only (immutable).
In GDScript, you can use make_read_only()
to make an array immutable, preventing any modifications.
Attempting to modify the contents of an array that has been made read-only will result in an error.
var array = ["apple", "lemon", "banana", "apple"]
array.make_read_only()
array[0] = "pineapple"
# Invalid set index '0' (on base: 'Array') with value of type 'String'