0

My game that I'm working on, my character can kill enemies but when the enemies die, they do not lose there collision box, and when I run the game and kill the enemies it comes up with the error in the title.

The entire enemy code is pasted below:

extends KinematicBody2D

const GRAVITY = 10
const SPEED = 30 
const FLOOR = Vector2(0, -1)

var velocity = Vector2()

var direction = 1

var is_dead = false

func _ready():
    pass 
    
func dead():
    is_dead = true
    velocity = Vector2(0, 0)
    $AnimatedSprite.play("dead")
    $CollisionShape2D.disabled = true
    $Timer.start()

func _physics_process(delta):
    if is_dead == false:
        velocity.x = SPEED * direction
        
        if direction == 1:
            $AnimatedSprite.flip_h = false
        else:
            $AnimatedSprite.flip_h = true 
            
        $AnimatedSprite.play("walk")
        
        velocity.y += GRAVITY
        
        velocity = move_and_slide(velocity, FLOOR)
    
    
    if is_on_wall():
        direction = direction * -1
        $RayCast2D.position.x *= -1
        
    if $RayCast2D.is_colliding() == false:
        direction = direction * -1
        $RayCast2D.position.x *= -1


func _on_Timer_timeout():
    queue_free()

If anyone can solve the problem that would be great because I can't figure it out.

Theraot
  • 31,890
  • 5
  • 57
  • 86
Snaza
  • 1

1 Answers1

0

As far as I can tell※, the solution is to use set_deferred to disable the collision shape:

$CollisionShape2D.set_deferred("disabled", true)

※: The error in the title of the question can only happen changing disabled, monitorable, mode or one_way_collision. And I only see disabled in the code. Edit: for what I find online, it could also be adding or removing nodes during a collision.

Theraot
  • 31,890
  • 5
  • 57
  • 86