#'get_child_count' on null value

2 messages · Page 1 of 1 (latest)

worn wraith
#

Im trying to call 'get_child_count' on a node but I keep getting an error saying I can't call it on a null value. What am I missing?

reef jackal
#

The node you're referencing to check the child count hasn't been loaded before you're attempting to access it. There's a few solutions for that, but the easiest in this case is just using the @onready annotation:
@onready var enemyCount = $Doors.get_child_count()
That'll make it so that your enemyCount gets set only after the _ready() function is called on your node instead of during the node's initialization.