Hello!
I am having trouble accessing the script of a newly instanced scene.
I have a scene called ExampleScene. The root node of that Scene has a script called ExampleScript.
extends Node
class_name ExampleScript
var _name
func init(name : string):
_name = name
In my main scene I want to instance the ExampleScene and call the ExampleScript:
var example = preload("res://ExampleScene.tscn")
func _ready():
var new_example = example.instance()
add_child(new_example)
var script : ExampleScript = new_example.get_script()
script.init("HAHAH") # breaks: Invalid Call. Nonexistent function init in base 'Nil'.
script is Null for some reason but when I test this
print(str(new_example.get_script() == ExampleScript)) # returns true.
it prints true.
What is going on here?
Cheers!