In one of my scripts container_box.gd
, in the _ready
function I'm calling this
app_manager = get_node("path_to_app_manager_here")
app_state = app_manager.state
app_state.some_signal.connect(some_function)
In app_manager.gd
I have the following
var state: AppState
func _ready():
state = AppState.new()
With this setup I was getting app_state as null in container_box.gd
. I noticed that this was happening because the AppManager node was defined after the ContainerBox in the tree. So moving the AppManager above the ContainerBox in the tree fixed the issue.
Another solution(which I went ahead with) to this was doing this directly instead of the ready function of AppManager
var state: AppState = AppState.new()
But this might not work for every scenario. What's the recommened practice for getting nodes/data in the ready function to ensure they are not null?