PhysicsDirectSpaceState in Godot 4: it is PhysicsDirectSpaceState3D now

By Eduardo Orellana · Updated

PhysicsDirectSpaceState is called PhysicsDirectSpaceState3D in Godot 4, and its queries take parameter objects instead of loose arguments. In a Godot 4 project, a variable typed PhysicsDirectSpaceState fails to parse with Could not find type "PhysicsDirectSpaceState" in the current scope.

AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.

Intel or AMD Chromebook, with Linux turned on.

Download for macOSDownload for Windows

What Godot is checking

GDScript resolves every type annotation when the script loads. PhysicsDirectSpaceState is not a class in Godot 4, so the analyzer stops with Could not find type and none of the script runs.

The converter carries PhysicsDirectSpaceState to PhysicsDirectSpaceState3D. get_world_3d().direct_space_state returns it; intersect_ray() takes a PhysicsRayQueryParameters3D, and intersect_shape() a PhysicsShapeQueryParameters3D.

Reproduce it

A Godot 3 variable typed PhysicsDirectSpaceState, in a Godot 4 project.

extends Node

var space: PhysicsDirectSpaceState

func _ready():
	print(space)

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 type "PhysicsDirectSpaceState" in the current scope.
   at: GDScript::reload (res://answers/physicsdirectspacestate-in-godot-4/repro.gd:3)
ERROR: Failed to load script "res://answers/physicsdirectspacestate-in-godot-4/repro.gd" with error "Parse error".
   at: load (modules/gdscript/gdscript_resource_format.cpp:46)

Fix it

The space state typed with its new name, queried with an empty ray. get_class() prints the physics server's own subclass of it, which is what the engine hands you.

extends Node3D

func _physics_process(_delta: float) -> void:
	var space: PhysicsDirectSpaceState3D = get_world_3d().direct_space_state
	var hit := space.intersect_ray(PhysicsRayQueryParameters3D.create(Vector3.ZERO, Vector3(0, -10, 0)))
	print(space.get_class(), ", hit: ", not hit.is_empty())
	set_physics_process(false)

What the fixed script prints

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

GodotPhysicsDirectSpaceState3D, hit: false

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 1573, PhysicsDirectSpaceState to PhysicsDirectSpaceState3D](https://github.com/godotengine/godot/blob/4.7.2-stable/editor/project_upgrade/renames_map_3_to_4.cpp#L1573), [PhysicsDirectSpaceState3D class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/PhysicsDirectSpaceState3D.xml).

Questions

When can I query the space?
In _physics_process(), when the physics state is consistent.
What is the 2D class?
PhysicsDirectSpaceState2D, from get_world_2d().direct_space_state.