0 votes

I'm coding with the help of a tutorial, and my debugger is going wild and crashing my game. It says that areasetshape is disabled it can't change it while flushing queries. It also says to use calldeffered() or setdeffered but I have no clue as a beginner, what that means.

The code:


my code

extends KinematicBody2D

const ACCELERATION =100
const MAX_SPEED=80
const FRICTION = 100000000000000000
enum{
    MOVE,
    ROLL,
    ATTACK
}


var state= MOVE
var velocity=Vector2.ZERO


onready var animationPlayer= $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState=animationTree.get("parameters/playback") 


func _process(delta):
    match state:
        MOVE:
            move_state(delta)
        ROLL:
            pass
        ATTACK:
            attack_state(delta)



func move_state(delta):
    var input_vector = Vector2.ZERO
    input_vector.x= Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
    input_vector.y= Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
    input_vector= input_vector.normalized()


    if input_vector != Vector2.ZERO:
        animationTree.set("parameters/Idle/blend_position", input_vector)
        animationTree.set("parameters/Run/blend_position", input_vector)
        animationTree.set("parameters/Attack/blend_position", input_vector)
        animationState.travel("Run")
        velocity= velocity.move_toward(input_vector*MAX_SPEED, ACCELERATION*delta)
    else:
        animationState.travel("Idle")
        velocity = velocity.move_toward(Vector2.ZERO, FRICTION*delta)

    velocity=move_and_slide(velocity)

    if Input.is_action_just_pressed("attack"):
        state = ATTACK

func attack_state(delta):
    animationState.travel("Attack")
    velocity = velocity.move_toward(Vector2.ZERO, FRICTION/2 * delta)
    velocity = move_and_slide(velocity)

func attack_animation_finished():
    state= MOVE

other code in game

extends Node2D

onready var animatedSprite = $AnimatedSprite


func _ready():
    animatedSprite.frame=0
    animatedSprite.play("default")



func _on_AnimatedSprite_animation_finished():
    queue_free()


extends Node2D

func create_grass_effect():
    var GrassEffect = load("res://Grass.tscn")
    var grassEffect= GrassEffect.instance()
    var world= get_tree().current_scene
    world.add_child(grassEffect)
    grassEffect.global_position = global_position
func _on_Area2D_area_entered(area):
    create_grass_effect()
    queue_free()
in Engine by (14 points)
edited by

UPDATE

Wrong word. Easy fix.

Edited to fix code formatting. Please use the {} button in future posts to format code. And, look at the Preview panel before posting. If it's not formatted there, it won't be formatted when you post.

1 Answer

0 votes

When physical object is queued free, its shapes are first disabled. Physical engine can't do this every frame, and it advises You to use call_deferred to slow down this process
So use call_deferred("queue_free") instead of just queue_free()evrywhere in tjhis code

by (8,099 points)
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.