Godot Version
4.1.2.stable.mono
Goal
I’m trying to get the Raycasts
node from the script of the Brain
node by doing
var raycasts : Node = get_node("../Raycasts")
under my _init()
function in my brain class.
Problem
When I do:
for i in RaycastsAmount:
var raycast : RayCast2D = RayCast2D.new()
raycast.set_target_position(Vector2(
sin((i / RaycastsAmount) * PI * 2) * RaycastsDistance,
cos((i / RaycastsAmount) * PI * 2) * RaycastsDistance))
raycasts.add_child(raycast)
I get this error:
Cannot call method add_child
on a null value.
and when I print raycasts
, it says it’s <Object#null>
I also tried doing
var raycasts : Node = $"../Raycasts"
but that gave me the same error.
What am I doing wrong?