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

Godot Version

4.3.stable

Code

extends Node2D

const BULLET = preload(“res://Scenes/bullet.tscn”)

@onready var muzzle: Marker2D = $Marker2D

func _process(_delta: float) → void:
look_at(get_global_mouse_position())

rotation_degrees = wrap(rotation_degrees, 0, 360)
if rotation_degrees > 90 and rotation_degrees < 270:
	scale.y = -1
else:
	scale.y = 1

if Input.is_action_just_pressed("fire"):
	var bullet_instance = BULLET.instansiate()
	get_tree().root.add_child(bullet_instance)
	bullet_instance.global_position = muzzle.global_position
	bullet_instance.rotation = rotation

Question

there isnt even something named PackedScene, I have no clue whats happening because instantiate is a function but it says its non existent can somebody tell me how to fix this?

You’ve spelled it correctly in your forum post but in code this line is spelled wrong with instansiate

The “PackedScene” is your BULLET, which is a preloaded scene.

1 Like

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