Increase var number when manually adding new node

Godot Version

4.7

Question

I have a node (“weak_point”) and I manually add them on different branches of a parent (a boss). Parent has a variable “weak_points” : integer (so that when it is zero the parent boss dies)

PARENT

= Branch_A

== weak_point_A

= Branch_B

== Branch_Ba

=== weak_point_B

Is it possible by code to increase this var “weak_points” each time I manually place the weak_point node?

(I currently wrote in the var number to how many nodes I added and it works fine. I’m just exploring other options)

Let the script on parent count them at startup.

var weak_points1 =  find_child(“weak_point_A”)
var weak_points =  find_children(“weak_point*”)

func _ready() → void:
print(weak_points1)
print(weak_points)

I did this but they both returns empty.

*fixed capital letters

Those find calls need to run inside _ready(), not at the top of the script. At class-body time the children usually aren’t there yet, so you get empty.

var weak_points := 0

func _ready() -> void:
	weak_points = find_children("weak_point*", "", true, false).size()
	print(weak_points)