Hello i need help with something

Godot Version

4.2.2

Question

my game crashes whenever one of the bullets hit their target and I’m not sure why. it gives me this error


I’m doing this level as part of a course and I’m doing all the same commands but it doesn’t work

Can you show your code?

1 Like

enemy code

extends PathFollow3D

@export var speed:float = 2.5

@export var max_health := 50

var current_health: int:
	set(health_in):
		current_health = health_in
		if current_health< 1:
			queue_free()

@onready var base = get_tree().get_first_node_in_group("base")

func _ready()->void:
	current_health=max_health


	

func _process(delta: float) -> void:
	progress += delta * speed

	if progress_ratio == 1.0:
		base.take_damage()
		set_process(false)
		

bullet code

extends Area3D

var direction := Vector3.FORWARD

@export var speed := 30.0

func _physics_process(delta: float) -> void:
	position=position+direction*speed*delta


func _on_timer_timeout() -> void:
	queue_free()


func _on_area_entered(area: Area3D) -> void:
	if area.is_in_group("enemy_area"):
		area.get_parent().currenth_health -= 25
		queue_free()

turret code

extends Node3D


@export var proyectil: PackedScene

var enemy_path: Path3D

@onready var rifle: MeshInstance3D = $body/head/rifle

@warning_ignore("unused_parameter")
func _physics_process(delta: float) -> void:
	var enemy = enemy_path.get_children().back()
	look_at(enemy.global_position,Vector3.UP, true,)

func _on_timer_timeout() -> void:
	var shot= proyectil.instantiate()
	add_child(shot)
	shot.global_position = rifle.global_position
	shot.direction = global_transform.basis.z

turret manager

extends Node3D

@export var turret:PackedScene

@export var enemy_path: Path3D

# Called when the node enters the scene tree for the first time.
func build_turret(turret_position: Vector3) ->void:
	var new_turret = turret.instantiate()
	add_child(new_turret)
	new_turret.global_position = turret_position
	new_turret.enemy_path = enemy_path

Are you sure that the error only occurs when the turret fires? Since your error occurs at 0:00 it could have to do with any initializing process…

i know there must be something else wrong because the turrets don’t aim at the path but the game crashes when the bullet hits the enemy

Other have this problem too. Some of them seem to have overlays from other apps running.

fo you know how to fix it?

Unfortunately no. Do you have any overlays active?

i dont know what is that

Some program that shows you your fps, gpu and cpu stats when in game. For example MSI afterburner.

That’s right now the only thing I come up with.

Can you try with the compatibility renderer instead ?

If that’s an issue with the Vulkan implementation of the engine, you might have better luck with the OpenGL renderer

Don’t know if it truly matters but I always add the child to the tree after setting it’s properties.

are you on linux? cold you run glxinfo -B and lspci -k | grep -EA3 'VGA|3D|Display' just to confirm that there’s nothing to do with gpu drivers