Projectile won't spawn

Godot Version

Godot 4.5.1 stable

Question

I’ve been trying to code an enemy for a while, I decided it was best before focusing on combat elements.

It’s getting there, my raycast is actually following the player now, however for some reason I can’t get the projectile to spawn. The conditions are set. I have a check in my projectile launcher script and it’s come up with true. So I’m very confused as to why this isn’t working. Help is appreciated.

extends CharacterBody3D

@onready var ray = $RayCast3D
const bullet = preload("res://bullet.tscn")
#var can_fire: bool = fireNow.playerSpotted
func _ready() -> void:
	pass
func _physics_process(delta: float) -> void:
	var target = Vector3(Autoload.player.position.x, Autoload.player.position.y, Autoload.player.position.z)
	var direction = position + target
	var direction_to_Player = target - global_position
	ray.target_position = ray.to_local(target)
	rotation.z = lerp_angle(rotation.z, atan2(direction_to_Player.x, direction_to_Player.y), delta/10)
	#var targetPosition = ray.direction_to(Autoload.player)
	if Autoload.playerSpotted == true:
		fire()
	if Input.is_action_just_pressed("check"):
		print(Autoload.playerSpotted)
func fire():
	var shoot = bullet.instantiate()
	add_sibling(shoot)

First check if fire() is getting called at all by putting a print statement or a debugger breakpoint into it.

Just did, yeah it’s being called

Next look at the remote scene tree at runtime if the scene nodes are being added where you expect them to be in the tree. You can also click on them and inspect their properties in the inspector, check if positions are correct etc.

Obviously there is more code not shown.
Two things, first the bullet spawner being in a process loop will spawn a lot of bullets without a flag or some system to stop that.
Second, bullets usually move. Are you quickly/instantly moving the bullet off screen (or queue_free) prior to seeing it?
I suppose check as well that bullet is a valid packed scene.