Need help Instanciating a Scene

Godot Version 4.4

Question

This is a Snippet of my code for a shooting mechanic

var bullet = preload("res://Scenes/bullet.tscn")
@onready var pos: Marker3D = $Mesh/Gun/pos

func _physics_process(delta: float) -> void:

	if Input.is_action_just_pressed("fire"):
		var instance = bullet.instance()
		instance.position = pos.global_position
		instance.transform.basis = pos.global_transform.basis
		get_parent().add_child(instance)

However I get the error Invalid call. Nonexistent function 'instance' in base 'PackedScene'.

What does it Mean and how do I fix it

I think you need .instantiate() rather than .instance() on a PackedScene.

2 Likes

Try

var instance = bullet.instantiate()
1 Like

@hexgrid @pauldrewett

if I change to that I just get Invalid call. Nonexistent function 'instanciate' in base 'PackedScene'.

instantiate(), not instanciate(); it’s the spelling.

2 Likes

thanks for saving my day the second time :wink:

1 Like

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