Reputation: 39
I am trying to create a topdown shooter with a player and a bullet on a separate scene. But whenever I run the game it says
Attempt to call function 'get_position' in base 'null instance' on a null instance.
BTW I am new to Godot.
The problem seems to be in this function:
const SPEED = 300
var bullet = preload("res://Mini-Scenes/Bullet.tscn")
func shoot():
var b = bullet.instance()
add_child(b)
b.set_position(position)
b.move_and_slide(Vector2(1, 0).rotated(rotation) * SPEED)
And I also don't think that I understand how instancing works,
so my questions are:
Upvotes: 2
Views: 7599
Reputation: 33
Alright, in order:
Node
of a scene and all its children, and copy-and-pastes them into memory. Then, when you add this Node
as child to another in the scene, _ready
is called, the Node
s begin to _process
and _physics_process
, as well as a few other things like receive events (as a Node
must be within a SceneTree
in order to interact with other nodes, and the most common way to add one to a tree is making it the child of another).For more information, see the documentation on Instancing
Upvotes: 0