Invalid assignment of property or key '…' with value of type '…' on a base object of type 'String' in Godot 4
By Eduardo Orellana · Updated
String has no property by that name to set; its length is a method, length(). title.length = 3 stops with Invalid assignment of property or key 'length' with value of type 'int' on a base object of type 'String'. To shorten a String, make a new one: title = title.left(3).
AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.
Intel or AMD Chromebook, with Linux turned on.
What Godot is checking
Setting a named property on a built-in value asks the value to set it. String exposes no settable properties, so the VM reports the property name, the value's type and the base type.
Strings in GDScript are values: methods such as left(), substr() and replace() return a new String and leave the original unchanged.
Reproduce it
A title String whose length is set like a property.
extends Node
func _ready() -> void:
var title = "Flock"
title.length = 3
print("after")
What Godot 4.7.2 prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
SCRIPT ERROR: Invalid assignment of property or key 'length' with value of type 'int' on a base object of type 'String'.
at: _ready (res://answers/invalid-assignment-of-property-or-key-on-string/repro.gd:5)
GDScript backtrace (most recent call first):
[0] _ready (res://answers/invalid-assignment-of-property-or-key-on-string/repro.gd:5)Fix it
Make a new String of the length you want.
extends Node
func _ready() -> void:
var title = "Flock"
title = title.left(3)
print(title, " ", title.length())
What the fixed script prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
Flo 3The same error in earlier Godot versions
Godot 4.2 and Godot 3.6 printed it as: Invalid set index 'length' (on base: 'String') with value of type 'int'. The cause and the fix are the same.
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 1235, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L1235).
Questions
- How do I change one character of a String?
- Index assignment works: title[0] = "B" replaces the first character. Setting a named property does not.
- Which built-in types have settable properties?
- Vectors (x, y, z), Color (r, g, b, a), Rect2 (position, size) and Transform types do. String, Array and Dictionary do not.
Related
- Invalid assignment of property or key on a base object of type 'Nil'
- Invalid access to property or key on type 'Dictionary'
- Every verified Godot 4 answer
- Invalid assignment of index '…' (on base: 'Array') with value of type '…' in Godot 4
- Invalid assignment of property or key '…' with value of type '…' on a base object of type 'Node2D' in Godot 4
- Out of bounds get index '…' (on base: 'Array') in Godot 4
- Invalid cast: can't convert a non-object value to an object type in Godot 4
- Invalid cast: could not convert value to '…' 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