Make sure to used fixedprocess instead of +process, otherwise the directspacestate() won't be accessible, and will return null, resulting in an error.
extends Sprite3D
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
var camera_pos = get_tree().get_root().get_camera().get_global_transform().origin
var halo_pos = get_global_transform().origin
var ray = get_world().get_direct_space_state().intersect_ray(halo_pos, camera_pos)
if(ray.empty()):
show()
else:
hide()