I looked through every while loop and await in my code (which was a lot) and didn’t find anything suspicious. But I did try individually removing specific nodes from the scene one by one to find out if any of them was causing it, and I believe the problem comes from this function:
if OWNER.is_attacking :
shoot_sound.set_pitch_scale(randf_range(0.9, 1.1))
shoot_sound.play()
var howmany : int = amount_r
var mouse_angle : float = get_angle_to(OWNER.aim_position)
var starting_rotation : float = (howmany*(PI/24))/2
for i : int in howmany :
var radius : int = 5
var theta : float = mouse_angle - starting_rotation + ((PI/10) * i)
### attack copier array key: [copier node, reorient aim?, copier damage multiplier]
print(OWNER.attack_copier_list)
for copier : Array in OWNER.attack_copier_list :
var needle : Area2D = spawn_projectile(needle_scene, copier[copier_node].global_position+Vector2(radius * cos(theta), radius * sin(theta)), base_damage * damage_multiplier * copier[copier_damage])
if copier[copier_reorient] :
needle.direction = copier[copier_node].get_angle_to(copier[copier_node].aim_position) - starting_rotation + ((PI/10) * i)
else :
needle.direction = mouse_angle - starting_rotation + ((PI/10) * i)
attack_fired.emit(attack_name)
available = false
await(get_tree().create_timer((1.0/5.0) * cooldown_r, false).timeout)
available = true
func _process(delta : float) -> void:
if available :
get_input()
The print function returns this:
[[PlayerCharacter:<CharacterBody2D#2756798729836>, false, 1.0], [Copy Doll:<Node2D#2764415586187>, false, 0.6], [@Node2D@41527:<Node2D#2765254447030>, false, 0.6], [@Node2D@41531:<Node2D#2765791317961>, false, 0.6], [@Node2D@41535:<Node2D#2766328188892>, false, 0.6]]
It seems that the more items there are in OWNER.attack_copier_list, the faster, on average, the game freezes and crashes. The printed array also tells me that, besides the player character, the first node in the array has the name “Copy Doll” as intended, but the following ones don’t, even though they’re instances of the same scene.
The code on the Copy Doll scene is this:
var speed : float = 0.0
var is_familiar : bool = true
@onready var sprite : Sprite2D = $Sprite2D
var sinewaving_factor : float = 0.0
var OWNER : Node2D
var aim_position : Vector2
func _process(delta: float) -> void:
sprite.position.y = 0.0 + 5.0 * sin(sinewaving_factor)
sinewaving_factor += 2.0 * delta
func _physics_process(delta: float) -> void:
var owner_local_aimpos : Vector2 = OWNER.aim_position - OWNER.global_position
aim_position = global_position + owner_local_aimpos
This is all helpful information, but I still can’t see what in any of these code snippets could be causing a freeze or a crash.