Trying to assign an array of type "Array" to a variable of type "Array[…]" in Godot 4
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.
More on this: Invalid access of index '…' on a base object of type: 'Array' in Godot 4
Reproduce it
An Array[String] variable given an untyped array.
More on this: Trying to assign a non-object value to a variable of type '…' in Godot 4
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
More on this: Invalid cast: could not convert value to '…' in Godot 4
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
["Ada", "Lin"] trueRun this fix with your agent
Flockbay is the Godot editor with an AI agent built in. Paste this into Flockbay's chat, or into Claude Code or Codex connected to Flockbay over MCP: the agent finds the cause in your project, applies the fix, runs the game headless and reads Godot's output to check it.
More on this: Invalid assignment on read-only value (on base: 'Array') in Godot 4
My Godot 4 project prints this error: "Trying to assign an array of type "Array" to a variable of type "Array[String]".". Find where it comes from and fix it. 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. Then run the game headless and check that Godot's output no longer shows it.Verified 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, Array.assign in the class reference.
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.
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free