Skip to content

Physics2DServerSW in Godot 4: Identifier "Physics2DServerSW" not declared

By Eduardo Orellana · Updated

Physics2DServerSW is called GodotPhysicsServer2D in Godot 4, but GDScript cannot name that class either: it is in ClassDB without being exposed to scripts. Call the PhysicsServer2D singleton, which runs on GodotPhysicsServer2D when physics/2d/physics_engine is DEFAULT or GodotPhysics2D.

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

When GDScript loads a script it resolves every identifier. Physics2DServerSW is not a class in Godot 4, so the analyzer stops with Identifier not declared in the current scope and none of the script runs.

When the project setting debug/gdscript/warnings/renamed_in_godot_4_hint is on, the analyzer looks the name up in the Godot 3 to 4 rename table and appends Did you mean to use with the new name. That table carries Physics2DServerSW to GodotPhysicsServer2D and Physics2DServer to PhysicsServer2D.

GodotPhysicsServer2D is the implementation behind the server, not a scripting API. The godot_physics_2d module creates it inside a PhysicsServer2DWrapMT and registers it with PhysicsServer2DManager under the name GodotPhysics2D, the default 2D server. On 4.7.2, ClassDB.class_exists("GodotPhysicsServer2D") prints true, but the GDScript analyzer only accepts a class that is also exposed. A class's exposed flag starts false and ClassDB::register_class sets it, and the module never calls register_class for GodotPhysicsServer2D, so the name still does not resolve. Scripts reach the server through the PhysicsServer2D singleton.

Reproduce it

A Godot 3 script that names Physics2DServerSW to create a circle shape, in a Godot 4 project. The scene is one Node with this script.

GDScript
extends Node

func _ready():
	var shape = Physics2DServerSW.circle_shape_create()
	print(shape)

What Godot 4.7.2 prints

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

SCRIPT ERROR: Parse Error: Identifier "Physics2DServerSW" not declared in the current scope. Did you mean to use "GodotPhysicsServer2D"?
   at: GDScript::reload (res://answers/physics2dserversw-in-godot-4/repro.gd:4)
ERROR: Failed to load script "res://answers/physics2dserversw-in-godot-4/repro.gd" with error "Parse error".
   at: load (modules/gdscript/gdscript_resource_format.cpp:46)

Fix it

Call the PhysicsServer2D singleton. The script also asks ClassDB whether GodotPhysicsServer2D exists, which class the singleton is, and which 2D physics engine the project uses.

GDScript
extends Node

func _ready() -> void:
	print("GodotPhysicsServer2D in ClassDB: ", ClassDB.class_exists("GodotPhysicsServer2D"))
	print("PhysicsServer2D in ClassDB: ", ClassDB.class_exists("PhysicsServer2D"))
	print("singleton class: ", PhysicsServer2D.get_class())
	print("physics engine: ", ProjectSettings.get_setting("physics/2d/physics_engine"))

	var shape := PhysicsServer2D.circle_shape_create()
	PhysicsServer2D.shape_set_data(shape, 16.0)
	print("shape type is circle: ", PhysicsServer2D.shape_get_type(shape) == PhysicsServer2D.SHAPE_CIRCLE)
	print("radius: ", PhysicsServer2D.shape_get_data(shape))
	PhysicsServer2D.free_rid(shape)

What the fixed script prints

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

GodotPhysicsServer2D in ClassDB: true
PhysicsServer2D in ClassDB: true
singleton class: PhysicsServer2D
physics engine: DEFAULT
shape type is circle: true
radius: 16.0

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.

Prompt
My Godot project was written for Godot 3 and Godot 4 stops on this: "Parse Error: Identifier "Physics2DServerSW" not declared in the current scope. Did you mean to use "GodotPhysicsServer2D"?". Port every use to Godot 4. Physics2DServerSW is called GodotPhysicsServer2D in Godot 4, but GDScript cannot name that class either: it is in ClassDB without being exposed to scripts. Call the PhysicsServer2D singleton, which runs on GodotPhysicsServer2D when physics/2d/physics_engine is DEFAULT or GodotPhysics2D. Then run the game headless and check Godot's output for errors.

Verified on Godot 4.7.2

Questions

Can I pick the 2D physics engine?
Yes, with the project setting physics/2d/physics_engine. Its default, DEFAULT, is currently equivalent to GodotPhysics2D, Godot's internal 2D physics engine. Select an explicit implementation if you want the project to stay on the same engine.
What is Physics2DServer called in Godot 4?
PhysicsServer2D. The rename table carries Physics2DServer to PhysicsServer2D, and that singleton is the one scripts call.
Where is box_shape_create for 2D?
PhysicsServer2D has no box_shape_create. A 2D box is rectangle_shape_create, and shape_set_data sets the rectangle's half-extents.

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

Download Flockbay free