#Getting Position of a random Marker2D

2 messages · Page 1 of 1 (latest)

brittle mortar
#

I have a randomly selected Marker2D node and I'm trying to get it's position in order to spawn an entity- how do I fix the error: "Attempt to call function 'global_position' in base 'null instance' on a null instance'.

`extends Node

@export var Spawnpoints : Array[Marker2D]
@export var Entity : PackedScene

Called when the node enters the scene tree for the first time.

func _ready():
var position_to_instance = Spawnpoints.pick_random()
var entity_instance = Entity.instantiate()
entity_instance.position = position_to_instance.global_position()
get_parent().call_deferred("add_child", entity_instance)
`

loud flame
#

is the array filled?