Adding "get_enemy_health()" causes enemies to stop spawning

Screen shot here to show what I mean.


enemies spawn in with 0 health, immediately die and then pay out 15 gold without ever appearing.

in this second screenshot you can see the code commented out and the game working fine.

extends Path3D

@export var difficulty_manager: Node
@export var enemy_scene: PackedScene
@onready var timer: Timer = $Timer


func spawn_enemy() -> void:
	var new_enemy = enemy_scene.instantiate()
	new_enemy.max_health = difficulty_manager.get_enemy_health()
	add_child(new_enemy)
	timer.wait_time = difficulty_manager.get_spawn_time()
	print(new_enemy.current_health)

I am unsure what is going on as when that specific line is added this issue occurs, when I comment the new_enemy.max_health = difficulty_manager.get_enemy_health() line out of the code everything runs perfectly fine.
I have double checked everything is the same name across scripts in both enemy_path.gd and difficulty_manager.gd and that is the case.

I am using GODOT 4.2.2.stable, could there have been some kind of minor change or bug?

Have you checked difficulty_manager.get_enemy_health() to make sure that it’s sampling from the curve correctly (and indeed that your curve doesn’t start with a y-value of 0)? It seems to me that this line is working correctly in the enemy scene, but it’s being fed 0-values by the difficulty manager.

1 Like

Oh man I feel dumb, I came back in to this lecture this morning with fresh eyes and your comment helped me find it within a couple minutes!

At some point I had broken the link unintentionally to the difficulty_manager.gd from enemy_path.gd!

I just needed to reconnect the exported node for the difficulty_manager script on the inspector and now everything is working perfectly!
When I checked everything this morning it was showing “Assign” since it was not connected.

In my journey to learn Godot this series has been the best in actually teaching and having a community to help. Thank you!

1 Like

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

Privacy & Terms