Invalid get index

When I try to place a turret while running the scene at 10:16, the game crashes and I get this error:

Invalid get index 'progress' (on base: 'Path3D').

Here is my code for turret.gd

extends Node3D

@export var projectile: PackedScene

var enemy_path: Path3D

@onready var turret_top: MeshInstance3D = $TurretBase/TurretTop

func _physics_process(delta: float) -> void:
	var enemy = find_best_target()
	if enemy:
		look_at(enemy.global_position, Vector3.UP, true) 

func _on_timer_timeout() -> void:
	var shot = projectile.instantiate()
	add_child(shot)
	shot.global_position = turret_top.global_position
	shot.direction = basis.z
	
func find_best_target() -> PathFollow3D:
	var best_target = null
	var best_progress = 0
	for enemy in enemy_path.get_children():
		if enemy is PathFollow3D:
			if enemy_path.progress > best_progress:
				best_target = enemy
				best_progress = enemy.progress
	return best_target

On line 25 I had “enemy_path.progress” instead of “enemy.progress”.

Interestingly, godot highlighted that line when it crashed but didn’t output that in the error.

I’ll leave the post up since I guess it’s worth documenting silly mistakes

1 Like

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

Privacy & Terms