I have fixed the 'issue' but not sure why this happens,
I have a simple spawn scene but kept getting an error
With the 'var's set in the function, this script works ok as expected...
(a spawn every second in this case)
var scene = load("res://Src/Spiderlet.tscn")
var pop = load("res://Src/Others/Burst.tscn")
func _ready():
pass
func _on_SpawnTimer_timeout():
var player = scene.instance()
var popped = pop.instance()
popped.position = Vector2(1000, 475)
get_parent().add_child(popped)
player.position = Vector2(1000, 500)
get_parent().add_child(player)
...but with the 'var's set at the start of the script, this one gives an error (on the second 'spawn', first one spawns ok)
Invalid set index 'position' (on base: 'null instance') with value of type 'Vector2'.
var scene = load("res://Src/Spiderlet.tscn")
var pop = load("res://Src/Others/Burst.tscn")
var player = scene.instance()
var popped = pop.instance()
func _ready():
pass
func _on_SpawnTimer_timeout():
popped.position = Vector2(1000, 475)
get_parent().add_child(popped)
player.position = Vector2(1000, 500)
get_parent().add_child(player)
Isnt the point of the variables declared at the top of the script mean they are globally accessable throughout the script?
Feels like this should work both ways.
Whats going on here?!