Loading in Scenes

Loaded scene not the right class?

Hi everyone, just learning Godot and unsure as to why my code isn’t working.
I am trying to add a variable small_health_bar which is a health bar scene to my Creature class using the following code:

var scene = preload(“res://Scenes/HealthBar.tscn”)
var small_health_bar = scene.instantiate()

This works fine, but it turns small_health_bar into a Node2D instead of a type HealthBar (a class I created) and it doesn’t run the script I wrote for HealthBar.

Kind of new and I can’t figure out what is going wrong. Any help would be appreciated!

Within the health bar scene, is the script actually attached to the root node?

Yeah it’s attached properly but I think the problem was just a broken _init() script

1 Like