'body->get_space()' error sometimes when I start my game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Yeldham

Sometimes, when I start my game, at the very beginning, this error pops up:

0:00:00:0484 - Condition ' !body->get_space() ' is true. returned: false
Time: 0:00:00:0484
C Error: Condition ' !body->get_space() ' is true. returned: false
C Source: servers/physics_2d/physics_2d_server_sw.cpp:969
C Function: body_test_motion

I don’t know if it’s a bug or something I’m doing wrong. Here is the segment of code where the error points out, in the move_and_slide function calling:

func _physics_process(delta):
direction = 0
if Input.is_action_pressed("ui_left"):
	direction -= 1
if Input.is_action_pressed("ui_right"):
	direction += 1

speed_current.x = lerp(speed_current.x, WALK_MAX_SPEED * direction,

if is_on_floor() and Input.is_action_just_pressed("ui_up"):
	speed_current.y = JUMP_FORCE

speed_current.y += GRAVITY * delta

speed_remaining = move_and_slide(speed_current, FLOOR_NORMAL)
speed_current.y = speed_remaining.y
if not is_on_floor():
	speed_current.x = speed_remaining.x

if is_on_floor() and position.y < camera.get_camera_position().y:
	camera.drag_margin_top = 0
elif camera.drag_margin_top == 0:
	camera.drag_margin_top = CAMERA_TOP_MARGIN

Ever figure out what the issue was?

Diet Estus | 2018-12-10 00:28

Hell, I stopped working on the project that this code was from since a good time. I actually don’t know.

Yeldham | 2018-12-13 22:11

I just got this error myself. AFAI can tell, it’s from trying to spawn a physics body in a place where it can’t be spawned, i.e colliding.

The reason i think this is because I got the error from spawning a large amount of kinematic 2d bodies into a relatively small space. The game crashed, and like I say, I think its from them not having room to be created without colliding with what’s alreay there.

ka0s420 | 2019-09-19 05:40

:bust_in_silhouette: Reply From: boruok

i’ve got this error when restarting current scene few times. Still don’t know how fix this.

:bust_in_silhouette: Reply From: 763484204

i got the same problem when i try to add a kinemoditybody2d to my scene, the error happend when the kinemoditybody2d call the move_and_slide and the linear_velocity that passed in is zero(only once),i updated the code to call the move_and_slide only when the velocity is not zero and the error solved
sorry my english is not good