I am writing a function that briefly introduces a script to the tree by creating a node and setting the script. While I am able to access regular variables via set_script(), any onready variable I try to access is never assigned (null).
How do I access onready vars using set_script()? There are some variables in these scripts that need to be onready, so I want to have a way to access them without always having these scripts active (I only want them instanced when they are relevant).
Below is a simplified version of my code to help illustrate my issue:
Instanced_Script.gd
var works = "This variable can be accessed and does not show up as NULL"
onready var doesnt_work = "This variable can't be accessed and instead shows up as NULL"
Main_Script.gd
var crashes_on_assign: String
var scriptNode = Node.new()
add_child(scriptNode)
var variableScript = load("[address of Instanced_Script.gd]")
scriptNode.set_script(variableScript)
print(scriptNode.works) #prints the string as expected
print(scriptNode.doesnt_work) #prints "Null"
crashes_on_assign = scriptNode.works #crashes with error (typed below)
#...the code continues but is not relevant to the issue...
ERROR: Trying to assign value of type 'Nil' to a variable of type 'String'.
Any help would be appreciated. Thank you!