I am having issues with adding children to a node I instantiated in script

Godot Version

Question

Please explain what issues you are having

Basically what is happening is that I am creating an instance of a mob and I want to add a child to this instance. Godot is throwing me an error saying I can’t instantiate on a null value.

Please show your code to help rest this, there’s not enough details here

‘’‘’
<func _on_shoot_timer_timeout():
var b = Bullet.instantiate()
owner.add_child(b)
b.transform = $AnimatedSprite2D/Muzzle.global_transform
var direction = (player_position - position).normalized()
var direction_to_mouse = direction
b.set_direction(direction_to_mouse)>

On the line owner.add_child(b) it is giving me the null error
‘’’

Have you assigned owner anywhere?

I was able to fix it using the

get_parent().add_child() function

Thanks for the Help

1 Like

owner is special here, it’s not the same as the parent, make sure it’s assigned if you’re going to use it, see here