0 votes
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 body.name == "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 = bodysetshapeasonewaycollision: Can't change this state while flushing queries. Use calldeferred() or setdeferred() 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():
    pass

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

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

        if direction == 1:
            $AnimatedSprite.flip_h = true
        else:
            $AnimatedSprite.flip_h = false
        $AnimatedSprite.play("idle")

        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":
            print("ciao")

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


func _on_Timer_timeout():
        call_deferred("free")
asked May 31 in Engine by MightyRat (55 points)

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

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

mind to share the project?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.