Skip to content

Commit 83d459e

Browse files
committed
fix
1 parent da0a43d commit 83d459e

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

characters/enemy/EnemySpawner.gd

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
extends Node2D
22

33
var spawn_positions = null
4-
#preload("res://characters/enemy/Enemy.tscn")
5-
6-
# Instead, you can load the resource dynamically:
7-
var enemy_scene = load("res://characters/enemy/Enemy.tscn")
4+
var enemy_scene = null
85

96
# Called when the node enters the scene tree for the first time.
107
func _ready():
118
randomize()
129
spawn_positions = $SpawnPositions.get_children()
13-
10+
11+
# Try to load the enemy scene
12+
enemy_scene = load("res://characters/enemy/Enemy.tscn")
13+
if enemy_scene == null:
14+
push_error("Failed to load enemy scene from: res://characters/enemy/Enemy.tscn")
15+
# Optionally disable the spawn timer if it exists
16+
if has_node("SpawnTimer"):
17+
$SpawnTimer.stop()
1418

1519
func spawn_enemy():
20+
# Check if we have valid spawn positions and enemy scene
21+
if spawn_positions == null or spawn_positions.size() == 0 or enemy_scene == null:
22+
push_error("Cannot spawn enemy: Missing required resources")
23+
return
24+
1625
var index = randi() % spawn_positions.size()
1726
var enemy = enemy_scene.instantiate()
18-
enemy.global_position = spawn_positions[index].global_position
19-
enemy.connect("enemy_died", Callable(get_tree().current_scene, "_on_enemy_died"))
20-
add_child(enemy)
27+
if enemy:
28+
enemy.global_position = spawn_positions[index].global_position
29+
enemy.connect("enemy_died", Callable(get_tree().current_scene, "_on_enemy_died"))
30+
add_child(enemy)
31+
else:
32+
push_error("Failed to instantiate enemy scene")
2133

2234
func _on_spawn_timer_timeout():
2335
spawn_enemy()

0 commit comments

Comments
 (0)