How to get collisions after move_and_slide() in Godot 4
After move_and_slide(), loop over get_slide_collision_count() and read each KinematicCollision2D with get_slide_collision(i): its get_collider() is what the body hit. Godot 3's get_slide_count() was renamed and fails to parse with Function "get_slide_count()" not found in base self. Did you mean to use "get_slide_collision_count()"?
AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.
Intel or AMD Chromebook, with Linux turned on.
What Godot is checking
move_and_slide() can collide several times in one call as it slides along surfaces. Each contact is kept until the next call, and get_slide_collision_count() says how many there were.
get_last_slide_collision() returns the last one directly, and is_on_floor(), is_on_wall() and is_on_ceiling() answer the common questions without reading collisions at all.
Reproduce it
A Godot 3 collision loop, in a Godot 4 project.
More on this: StaticBody in Godot 4: it is StaticBody3D now
extends CharacterBody2D
func _physics_process(_delta):
move_and_slide()
for i in get_slide_count():
print(get_slide_collision(i).get_collider())
What Godot 4.7.2 prints
More on this: Quat in Godot 4: it is Quaternion now
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
SCRIPT ERROR: Parse Error: Function "get_slide_count()" not found in base self. Did you mean to use "get_slide_collision_count()"?
at: GDScript::reload (res://answers/how-to-get-collisions-after-move-and-slide-in-godot-4/repro.gd:5)
ERROR: Failed to load script "res://answers/how-to-get-collisions-after-move-and-slide-in-godot-4/repro.gd" with error "Parse error".
at: load (modules/gdscript/gdscript_resource_format.cpp:46)Fix it
A body falling onto a StaticBody2D named Floor, reporting the first contact.
extends CharacterBody2D
func _physics_process(_delta: float) -> void:
velocity = Vector2(0, 300)
move_and_slide()
for i in get_slide_collision_count():
var collision := get_slide_collision(i)
print("hit ", collision.get_collider().name, ", normal ", collision.get_normal(), ", on floor: ", is_on_floor())
set_physics_process(false)
What the fixed script prints
More on this: PoolStringArray in Godot 4: it is PackedStringArray now
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
hit Floor, normal (0.0, -1.0), on floor: trueRun 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: How to get a random number in Godot 4: randi_range() and randf_range()
How to get collisions after move_and_slide() in Godot 4 After move_and_slide(), loop over get_slide_collision_count() and read each KinematicCollision2D with get_slide_collision(i): its get_collider() is what the body hit. Godot 3's get_slide_count() was renamed and fails to parse with Function "get_slide_count()" not found in base self. Did you mean to use "get_slide_collision_count()"? Where this calls for a change in my Godot 4 project, make it, 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: gdscript_analyzer.cpp line 3767, the message with its hint, CharacterBody2D.get_slide_collision in the class reference.
Questions
- Why is the count 0 when I call it in _process()?
- Collisions are from the last move_and_slide(), which runs in _physics_process(). Read them right after it.
- How do I push a RigidBody2D I walk into?
- Read the collision's collider, check it is a RigidBody2D, and call apply_central_impulse(-collision.get_normal() * force).
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free