Hi all.
In my project "enemies" are all the same scene, but on setup()
they are randomized and some parameters are changed. In case of size, I also need to resize CircleShape2D
, for their's "hitbox" be same as "image" player see.
Scene tree:
KinematicBody2D
->CollisionShape2D
->Sprite
setup()
called after adding "enemy" to main scene, to set it position and movement direction, it's not _ready()
(dunno why I do it like this)
At first I set default CircleShape2D
to CollisionShape2D and on setup()
set new radius, but in this case actual radius sometimes not match the sprite size.
Then I decided to remove default CircleShape2D
from CollisionShape2D and add it in the code on setup()
. This time all work as intended, BUT debugger create new error every time new "enemy" is spawned. Stack trace lead me to
get_node("collision").set_shape(CircleShape2D.new())
Also, in cmd I can see error, that appears on every "enemy" spawn:
CollisionObject2D::set_shape: Index p_shape_idx out of size (shapes.size()).
The Question: why debugger throw this error and no process disruption was seen during game?
Maybe I should just create separate scenes for each enemy and forget about this?