Condition ' !data.tree ' is true. returned: __nul

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

Hey, how is it possible that the tree isn’t accessible?

How can you get notified when it will so that you can make up the things you needed to do in the script when the tree wasn’t accessible.

To get this message, it’s simple :

  • create a scene
  • create a Node and add it to the scene
  • add it a tool script
  • write func _ready():
  • then save the file, save the scene, and look at the ouput console
:bust_in_silhouette: Reply From: Yiannis Charalambous

Found out how to fix this in GDScript really simply:
Wrap your tree access code in this if statement:

if get_owner() != null:
  # Stuff you want to do with the tree.
:bust_in_silhouette: Reply From: d2clon

This is what worked for me in Godot 4:

if self.is_inside_tree(): 
	# Stuff you want to do with the tree.