@@ -7,11 +7,20 @@ const BlocksCatalog = preload("res://addons/block_code/code_generation/blocks_ca
77const OptionData = preload ("res://addons/block_code/code_generation/option_data.gd" )
88const Types = preload ("res://addons/block_code/types/types.gd" )
99
10+ enum SpawnParent {
11+ THIS , ## Spawned scenes are children of this node
12+ SCENE , ## Spawned scenes are children of the scene
13+ }
1014enum LimitBehavior { REPLACE , NO_SPAWN }
1115
1216## The scenes to spawn. If more than one are provided, they will be picked randomly.
1317@export var scenes : Array [PackedScene ] = []
1418
19+ ## The node that the spawned scenes should be a child of. If you want to move
20+ ## the SimpleSpawner without moving the scenes it has already spawned, choose
21+ ## SCENE.
22+ @export var spawn_parent : SpawnParent
23+
1524## The period of time in seconds to spawn another component. If zero, they won't spawn
1625## automatically. Use the "Spawn" block.
1726@export_range (0.0 , 10.0 , 0.1 , "or_greater" ) var spawn_frequency : float = 0.0 :
@@ -41,7 +50,7 @@ func get_custom_class():
4150func _remove_oldest_spawned ():
4251 var spawned = _spawned_scenes .pop_front ()
4352 if is_instance_valid (spawned ):
44- remove_child (spawned )
53+ spawned . get_parent (). remove_child (spawned )
4554
4655
4756func _set_spawn_fraquency (new_frequency : float ):
@@ -60,7 +69,7 @@ func spawn_start():
6069 _timer .wait_time = spawn_frequency
6170 _timer .timeout .connect (spawn_once )
6271 _timer .start ()
63- spawn_once ()
72+ spawn_once . call_deferred ()
6473
6574
6675func spawn_stop ():
@@ -90,7 +99,12 @@ func spawn_once():
9099 var scene : PackedScene = scenes .pick_random ()
91100 var spawned = scene .instantiate ()
92101 _spawned_scenes .push_back (spawned )
93- add_child (spawned )
102+ match spawn_parent :
103+ SpawnParent .THIS :
104+ add_child (spawned )
105+ SpawnParent .SCENE :
106+ get_tree ().current_scene .add_child (spawned )
107+ spawned .position = global_position
94108
95109
96110func do_set_spawn_frequency (new_frequency : float ):
0 commit comments