PhysicsDirectSpaceState in Godot 4: it is PhysicsDirectSpaceState3D now
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.
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.
More on this: Physics2DDirectBodyState in Godot 4: it is PhysicsDirectBodyState2D now
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: falseRun 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: StreamTexture in Godot 4: Could not find type "StreamTexture"
My Godot project was written for Godot 3 and Godot 4 stops on this: "Parse Error: Could not find type "PhysicsDirectSpaceState" in the current scope.". Port every use to Godot 4. 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. 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 1573, PhysicsDirectSpaceState to PhysicsDirectSpaceState3D, PhysicsDirectSpaceState3D class reference.
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.
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free