How to instantiate a scene more than one time

Godot Version

4.2.2.stable

Question

The code only spawns the enemy once how do I make it spawn every time the timer runs out. Also it prints “It works” every 1 second so it is not the timer.

extends Node2D

@export var Enemy = preload(“res://Scenes/Enemy1.tscn”)
var speed = 100
var direction = -1
var I = true
@onready var timer = $“…/Timer”

func _on_timer_timeout():
var spawn2 = Enemy.instantiate()
add_child(spawn2)
spawn2.transform = get_node(“/root/EnemySpawn/Marker2D3”).global_transform
print(“It works”)

func _process(delta):
position.x += speed * direction * delta

Are you sure that additional instances aren’t being spawned and you just can’t see them? Check the remote tab of the scene tree during runtime

1 Like

You’re spawning each item in the same place, and not moving them apart.