Your child
variable is local to the instance_child()
function (because it was defined inside that function). Because of that, the child
variable is not recognized anywhere outside of that function. To fix it, you need to define the child
variable outside of any function. So, this:
onready var instanced_child = preload("res://child.tscn")
var child # <--- defined here
func instance_child():
child = instanced_child.instance() # <--- note, no "var" keyword
self.add_child(child)
func do_something_with_child():
$child.do_something()