# Reference in Godot 4: it is RefCounted now

Reference is called RefCounted in Godot 4: the base class for objects freed automatically when nothing refers to them. In a Godot 4 project, extends Reference fails to parse with Could not find base class "Reference".

Source: https://flockbay.com/godot/reference-in-godot-4/ · Updated 2026-10-30

## What Godot is checking

GDScript resolves the class after extends when the script loads. Reference is not a class in Godot 4, so the script fails to parse and nothing in it runs.

The converter carries Reference to RefCounted. A script with no extends line already extends RefCounted, so extends Reference can simply be deleted.

## Reproduce it

A Godot 3 script that extends Reference, in a Godot 4 project. The scene is one Node carrying it.

```
extends Reference

func _ready():
	print("ready")

```

## What Godot 4.7.2 prints

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

SCRIPT ERROR: Parse Error: Could not find base class "Reference".
   at: GDScript::reload (res://answers/reference-in-godot-4/repro.gd:1)
ERROR: Failed to load script "res://answers/reference-in-godot-4/repro.gd" with error "Parse error".
   at: load (modules/gdscript/gdscript_resource_format.cpp:46)
```

## Fix it

A data class that extends RefCounted, freed when its last reference goes.

```
extends Node

class Stats extends RefCounted:
	var hp := 10

func _ready() -> void:
	var stats := Stats.new()
	var watch: WeakRef = weakref(stats)
	print("refs: ", stats.get_reference_count(), ", is RefCounted: ", stats is RefCounted)
	stats = null
	print("freed: ", watch.get_ref() == null)

```

## What the fixed script prints

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

refs: 1, is RefCounted: true
freed: true
```

## 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 project was written for Godot 3 and Godot 4 stops on this: "Parse Error: Could not find base class "Reference".". Port every use to Godot 4. Reference is called RefCounted in Godot 4: the base class for objects freed automatically when nothing refers to them. In a Godot 4 project, extends Reference fails to parse with Could not find base class "Reference". Then run the game headless and check Godot's output for errors.
```

## 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: [renames_map_3_to_4.cpp line 1467, Reference to RefCounted](https://github.com/godotengine/godot/blob/4.7.2-stable/editor/project_upgrade/renames_map_3_to_4.cpp#L1467), [RefCounted class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/RefCounted.xml).

## Questions

### Should a data class extend RefCounted or Resource?

Resource when it should be saved to disk or edited in the Inspector; RefCounted when it only lives while the game runs.

### Can I free a RefCounted with free()?

No; it frees itself when the last reference goes, and free() is refused.

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: [Attempted to free a RefCounted object in Godot 4](/godot/attempted-to-free-a-refcounted-object/), [Spatial in Godot 4: Could not find base class "Spatial"](/godot/spatial-in-godot-4/), [Could not find base class "KinematicBody2D" in Godot 4: it is CharacterBody2D now](/godot/kinematicbody2d-in-godot-4/), [Camera in Godot 4: it is Camera3D now](/godot/camera-in-godot-4/), [Every verified Godot 4 answer](/godot/), [Does Flockbay change my Godot project?](/docs/does-flockbay-change-my-godot-project/)
