Weird error on spawner

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MightyRat
extends Area2D
var spawn = false
export (int) var xLoc = -20
export (int) var yLoc = 0
export (int) var direction = -1
export (int) var time = 3
var enemy = preload("res://WarriorGolem.tscn")

func ready():
	connect("body_enter", self, "on_GolemSpawner_body_entered")

    func _on_GolemSpawner_body_entered(body):
    	if == "Player":
    			spawn = true
    			var e = enemy.instance()
    			get_parent().add_child(e) #ERROR HERE!
    			e.position = Vector2(xLoc, yLoc)
    			e.direction = direction
    			$CollisionShape2D.call_deferred("set_disabled", true)
    			yield(get_tree().create_timer(time), "timeout")
    			$CollisionShape2D.call_deferred("set_disabled", false)
    			if direction == 1:
    				$Sprite.flip_h = true

Error = body_set_shape_as_one_way_collision: Can’t change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.

I can’t understand what type of error is that, the child added is a simple enemy with this script:

extends KinematicBody2D

const GRAVITY = 10
export (int) var SPEED = 60
const FLOOR = Vector2(0, -1)
export (int) var life = 0
var velocity = Vector2()

var direction = 1

var is_dead = false

func _ready():

func dead():
	life -= 1
	if life < 0:
		is_dead = true
		velocity = Vector2(0, 0)
		$CollisionShape2D.call_deferred("set_disabled", true)

func _physics_process(delta):
	if is_dead == false:
		velocity.x = SPEED * direction

		if direction == 1:
			$AnimatedSprite.flip_h = true
			$AnimatedSprite.flip_h = false

		velocity.y += GRAVITY

		velocity = move_and_slide(velocity, FLOOR)

	if is_on_wall():

		direction = direction * -1
		$RayCast2D.position.x *= -1

	if $RayCast2D.is_colliding():
		if $RayCast2D.get_collider().name == "Player":

	if get_slide_count() > 0:
		for i in range(get_slide_count()):
			if "Player" in get_slide_collision(i)
				get_parent().get_node("Player").gameover = 1

func _on_Timer_timeout():

do you have any one_way_collision object in the project?
is the error in the enemy node or in the spawner? (try spawn some other script-less kinematic body and see what happens)
also, usually the debugger stops the program and show which line is the one creating the error, might be usuefull to know

Andrea | 2020-06-01 15:08

The game doesn’t stop, the debugger just show this error, the bugged line is the one I signed with “ERROR HERE” in the spawner script

MightyRat | 2020-06-02 09:29

mind to share the project?

Andrea | 2020-06-03 10:10