Skip to content

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.

Download for macOSDownload for WindowsDownload for Linux

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.

GDScript
extends Node

func _ready() -> void:
	var title = "Flock"
	title.length = 3
	print("after")

What Godot 4.7.2 prints

Output
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.

GDScript
extends Node

func _ready() -> void:
	var title = "Flock"
	title = title.left(3)
	print(title, " ", title.length())

What the fixed script prints

Output
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

Flo 3

Run 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: How to remap input actions in code in Godot 4: InputMap and keycode

Prompt
My Godot 4 project prints this error: "Invalid assignment of property or key 'length' with value of type 'int' on a base object of type 'String'.". Find where it comes from and fix it. 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). Then run the game headless and check that Godot's output no longer shows it.

The 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.

More on this: How to get the class name of a node in Godot 4: get_class() and get_global_name()

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.

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.

Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.

Download Flockbay free