# Invalid assignment of property or key '…' with value of type '…' on a base object of type 'String' in Godot 4

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

Source: https://flockbay.com/godot/invalid-assignment-of-property-or-key-on-string/ · Updated 2026-10-30

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

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

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

Download Flockbay free: Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot. https://flockbay.com/download/

Related: [Invalid assignment of property or key '…' with value of type '…' on a base object of type 'Node2D' in Godot 4](/godot/invalid-assignment-of-property-or-key-on-node2d/), [Invalid assignment on read-only value (on base: 'Array') in Godot 4](/godot/invalid-assignment-on-read-only-value/), [Invalid access to property or key '…' on a base object of type 'Dictionary' in Godot 4](/godot/invalid-access-to-property-or-key-on-dictionary/), [Invalid assignment of property or key 'text' with value of type 'String' on a base object of type 'Nil' in Godot 4](/godot/invalid-assignment-of-property-or-key-on-nil/), [How to get the class name of a node in Godot 4: get_class() and get_global_name()](/godot/how-to-get-the-class-name-of-a-node-in-godot-4/), [Every verified Godot 4 answer](/godot/), [How do I see Godot’s output and errors in Flockbay?](/docs/how-do-i-see-godots-output-in-flockbay/)
