How to properly reference a node?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fronquak

I have been partly following a tutorial and I got stuck here where animationTree is null, despite being in an onready var.

The error I am getting is: Attempt to call function ‘get’ in base ‘null instance’ on a null instance.

Am I doing something wrong? Do I need to provide more information?

:bust_in_silhouette: Reply From: estebanmolca

Variant get(property: String) const

Returns the Variant value of the given property. If the property
doesn’t exist, this will return null.

I think the error is because the searched property does not exist. If you use for example get (“active”) the function does not return null. Can you pass the tutorial link?

(Now that I look closely, what I said does not make sense, that the get function returns null is one thing and that the variable where it is executed is null is another)

Thanks for replying!

I tried a bit of debugging and commented out the second line. I added a print line in the ready function to print the animationTree object. The output showed a null object and then the animationTree! But the second line does not work when I uncomment it. Does this help in solving the problem?

enter image description here

fronquak | 2021-03-07 03:23

mmm weird, it’s like it waits for another node to load to stop being null. Take a good look at your entire project and the loading order. What animates with the animationTree? Maybe it animates some property that is loaded later in the scene? Go through all of that and if you still have errors try isolating the parts in new scenes or even a new project to find the source of the error.

estebanmolca | 2021-03-07 03:57

Another thing, the only way I see for ready () to print the same line 2 times is for that script to run 2 times. What does the script have in main?

estebanmolca | 2021-03-07 04:14

I am all out of ideas now. I removed every script and [object:null] still shows up.

enter image description here

EDIT: I deleted the Main node and it still shows up

fronquak | 2021-03-07 06:18

Do you have any script running in autoload?

If you switch the tab to remote with the game running, you will be able to see everything that is loading and the order, including any scripts that may be loading from autoload.

estebanmolca | 2021-03-07 10:52

That’s it, thank you so much! Can’t believe I forgot about autoload… Add an answer and I’ll mark it as solved. Thanks again :slight_smile:

fronquak | 2021-03-07 11:15

No problem, I’m glad you found the bug.

estebanmolca | 2021-03-07 11:18