Okay, so I have this error that’s driving me nuts as it’s a common error and yet I don’t know how to fix it. It goes something like this:
Attempt to call function 'get_children' in base 'null instance' on a null instance.
Now typically, an error like this means that I can’t get a node properly due to a typo but, I don’t think that’s the case. The IDE told me that the error because with this line of code:
for r in shotgun_blast.get_children():
r.cast_to.x = rand_range(spread,-spread)
r.cast_to.y = rand_range(spread,-spread)
However, this line of code only had an error my ready():
function which looks like this in:
func _ready():
max_ammo = ammo
randomize()
for r in shotgun_blast.get_children():
r.cast_to.x = rand_range(spread,-spread)
r.cast_to.y = rand_range(spread,-spread)
Elsewhere, this code runs perfectly well like when I used it in the firing_shotgun():
func firing_shotgun():
if Input.is_action_pressed("fire") and not ammo <= 0:
if using == false:
using = true
ammo -= 1
anim_player.playback_speed = firing_speed
anim_player.play(firing_anim)
for r in shotgun_blast.get_children():
r.cast_to.x = rand_range(spread,-spread)
r.cast_to.y = rand_range(spread,-spread)
if r.is_colliding():
bullet_holes(r)
if r.get_collider().is_in_group("enemy"):
r.get_collider().health -= 50
yield(anim_player,"animation_finished")
using = false
elif using == false and not anim_player.is_playing():
anim_player.playback_speed = 1
anim_player.play("idle")
ammo_count.text = "Ammo:" + String(ammo)
The fact that the error only shows up in the Ready() function and firingshotgun() implies that I do have proper access to the node shotgunblast. Could you please him me?