Invalid call. Nonexistent function 'instanciate' in base 'PackedScene'

Godot Version

4

Question

what is wrong with this??? i get this error
" Invalid call. Nonexistent function ‘instanciate’ in base ‘PackedScene’. "

This is the code i put in
var bullet = preload(“res://bullet.tscn”)

func toshoot():
> var bullet_instance = bullet.instanciate()
> bullet_instance.position = get_global_transform()
> bullet_instance.rotation_degrees = rotation_degrees
> bullet_instance.apply_impulse(Vector2(),Vector2(bulletspeed,0).rotated(rotation))
> get_tree().get_root().call_deferred(“add_child”,bullet_instance)

You need to call “instantiate” instead of “instanciate”

1 Like

haha. i feel so dumb. now there is another problem

this is the error
Invalid set index ‘position’ (on base: ‘RigidBody2D’) with value of type ‘Transform2D’.

As far as I know, bullet_instance.position is of type Vector2, while get_global_transform() returns a Transfrom2D type, hence you cannot set position to be equal to Transform2D, as it expects a Vector2.
What you can do is set the X position first, then the Y position, as the Transform2D that get_global_transform() returns does contain the X and Y values.

1 Like

It should be:

bullet_instance.position = global_position

If you want to assign with the global position of what you’re calling from

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.