Trying to assign an array of type "Array" to a variable of type "Array[…]" in Godot 4
By Eduardo Orellana · Updated
The variable is a typed array, Array[String], and the value is an untyped Array, which Godot 4 will not store in it even if its elements would fit. names = raw stops with Trying to assign an array of type "Array" to a variable of type "Array[String]". Copy the elements in with names.assign(raw), or build the array as Array[String] from the start.
AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.
Intel or AMD Chromebook, with Linux turned on.
What Godot is checking
A typed array is a different type from an untyped one, and assignment checks the array's element type, not its contents. An untyped Array is refused before any element is looked at.
assign() copies element by element and converts or checks each one, so it fills a typed array from an untyped one.
Reproduce it
An Array[String] variable given an untyped array.
extends Node
func _ready() -> void:
var names: Array[String] = []
var raw = ["Ada", "Lin"]
names = raw
print("after")
What Godot 4.7.2 prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
SCRIPT ERROR: Trying to assign an array of type "Array" to a variable of type "Array[String]".
at: _ready (res://answers/trying-to-assign-an-array-of-type-to-a-variable-of-type-array/repro.gd:6)
GDScript backtrace (most recent call first):
[0] _ready (res://answers/trying-to-assign-an-array-of-type-to-a-variable-of-type-array/repro.gd:6)Fix it
Copy the elements with assign().
extends Node
func _ready() -> void:
var names: Array[String] = []
var raw = ["Ada", "Lin"]
names.assign(raw)
print(names, " ", names.get_typed_builtin() == TYPE_STRING)
What the fixed script prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
["Ada", "Lin"] trueVerified on Godot 4.7.2
Both scripts on this page were run headless on Godot 4.7.2 (4.7.2.stable.mono.official.ed1daf0bf) on 18 October 2026, and the output above is what Godot printed, unedited.
Where the check lives in Godot's source: [gdscript_vm.cpp line 1477, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L1477), [Array.assign in the class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/Array.xml).
More on this: Trying to assign a non-object value to a variable of type '…' in Godot 4
Questions
- Why does get_children() not fit an Array[Node2D]?
- get_children() returns Array[Node]. Assigning it to Array[Node2D] fails for the same reason; use assign(), which checks each child is a Node2D.
- Does assign() fail on a wrong element?
- Yes. An element that is not the array's type makes assign() report an error and leave the array unchanged.
Related
- Trying to assign value of type 'String' to a variable of type 'int'
- Invalid assignment of index (on base: 'Array')
- Every verified Godot 4 answer
- Trying to assign a non-object value to a variable of type '…' in Godot 4
- Invalid access of index '…' on a base object of type: 'Array' in Godot 4
- Cannot assign a new value to a constant in Godot 4
- Cannot call method '…' on a null value in Godot 4
- Trying to return a value of type "…" from a function whose return type is "…" in Godot 4
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free