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 Windows

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.

extends Node

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

What Godot 4.7.2 prints

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.

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

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

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 6 October 2026, and the output above is what Godot printed, unedited.

Where the check lives in Godot's source: [gdscript_analyzer.cpp lines 4679 to 4687, the message and the rename hint](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_analyzer.cpp#L4679), [renames_map_3_to_4.cpp lines 1567 and 1568, Physics2DServer and Physics2DServerSW](https://github.com/godotengine/godot/blob/4.7.2-stable/editor/project_upgrade/renames_map_3_to_4.cpp#L1567), [godot_physics_2d register_types.cpp, GodotPhysicsServer2D registered as the GodotPhysics2D server](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/godot_physics_2d/register_types.cpp#L39), [gdscript_analyzer.cpp line 6619, a class must exist in ClassDB and be exposed](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_analyzer.cpp#L6619), [class_db.h lines 151 and 252, exposed starts false and register_class sets it](https://github.com/godotengine/godot/blob/4.7.2-stable/core/object/class_db.h#L151), [physics/2d/physics_engine in the ProjectSettings class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/ProjectSettings.xml#L2547), [PhysicsServer2D class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/PhysicsServer2D.xml).

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.