0 votes

Hello, again haha. I'm currently experiencing an issue where the game crashes with a breakpoint and I'm unsure what causes this. I am making a hurtbox/hitbox system and, at first, the game used to crash when I actually entered the hitbox of the enemy, but now it crashes every time I even open the project. I made an EnemyBase inhereted from an EntityBase, then added the following script to it:

extends KinematicBody2D

export(int) var hp_max: int = 100
export(int) var hp: int = hp_max

var velocity: Vector2 = Vector2.ZERO
export (int) var SPEED: int = 75

onready var animatedsprite = $AnimatedSprite
onready var collshape = $CollisionShape2D

func _physics_process(_delta): move()

func move(): velocity = move_and_slide(velocity)

func die(): queue_free()

func _on_Hurtbox_area_entered(hitbox): var base_damage = hitbox.damage self.hp -= base_damage print(hitbox.get_parent().name + "'s hotbox touched " + name + "'s hurtbox and dealt " + str(base_damage))

The Hitbox of the enemy just has the damage variable, this is Hitbox.gd:

extends Area2D

export(int) var damage: int = 10

Any ideas on how to fix this?

Godot version v3.5.1
in Engine by (35 points)

What error are you getting? And which line has the breakpoint?

wait what ? The problem is that game crashes after setting up breakpoint in the code ? ;)

When you say "crash", you mean the whole of Godot crashes, or just your game?

1 Answer

0 votes

It looks like in your _on_Hurtbox_area_entered(hitbox) function, any area at all can trigger this code. This is a problem if the triggering area does not contain a variable for damage, like you are assuming when you say var base_damage = hitbox.damage.

Try to ensure that the triggering area is the correct area. You can assign the triggering area to a group, and then in the _on_Hurtbox_area_entered(hitbox), return from the function immediately if the triggering area is not in the correct group.

As to why the game crashes immediately upon opening it, if there is an enemy overlapping any other area upon start-up, it will crash because of the above reasons (hard to say for certain what is happening without any other pictures or information, though).

Good luck!

by (177 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.