Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | crookedvult |
I tried to google for this, but couldn’t find the terms I needed, I think, every result was random spawning.
I’m trying to spawn an enemy instance at the position of a predetermined point, where I have each point as a Position2D node named Spawn1 - Spawn 8, and they’re all the child of a Node2D called Spawnpoints. My script is on the root node, a Node2D named SpawnManager. My code looks like this:
extends Node2D
onready var enemy1 = preload("res://Enemies/Enemy.tscn")
onready var SpawnPoints = $SpawnPoints
var possiblePoints = SpawnPoints.get_children()
var selectedSpawn
func _on_EnemySpawnTimer_timeout():
selectedSpawn = possiblePoints[rand_range(0,7)]
var Enemy_instance = enemy1.instance()
Enemy_instance.position = selectedSpawn.position
When I run it, I get the error "Invalid call. Nonexistant function ‘get_children’ in base ‘Nil.’ "