Sending random spawned enemy health information to a central HUD?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Arkinum

I’m making a game that has a centralized HUD at the top of the screen, much like the old school 2D beat em ups.

I’ve been having success with using signals for the player, but have hit a snag. Most of the enemys in my game are just randomly instantiated from spawn nodes, and don’t exist in the scene tree until they are spawned.

So how would I go about making a reference in the main scene node for nodes(enemys) that haven’t been instanced yet?


Maybe you could have a central event queue where they can signal their health? I’ve heard of a programming pattern which may help. It sounds complicated, but it may be what you require.

Ertain | 2018-06-20 06:59

Don’t quite understand the last paragraph. Could you explain that a little?

duke_meister | 2018-06-20 08:46


Thank you. You’re right, it dose look quite complicated. But I’ll look into it.


Basically I learned how to make and use custom signals though this tutorial:

From what I understand, I need to .connect() anything that has a signal to be passed though the main scene node to my HUD.

I already instanced the player and hud under the main scene node via the editor, so I can reference them very easily.

But the enemys are instanced randomly when the player hits the spawns collider. So there are no enemies in the scene to reference.

I’ve tried to reference the .tscn each enemy type (and signal) resides in via:
onready var EnemyVarName = preload (“Where/I/keep/the/file”).

But Godot just screams at me about not being able to access a packed scene or something like that.

Arkinum | 2018-06-20 11:53

Oh ok I connect up dynamically created instanced nodes in script. I’m not sure why this isn’t an option for you?

duke_meister | 2018-06-20 12:29

Thanks for the reply. Yea I just figured that out by messing around and looking back at the tutorial.

Arkinum | 2018-06-20 13:15

:bust_in_silhouette: Reply From: Arkinum

OK I think I figured it out.

I put my instancing code into the main scene script then referenced the spawner in the scene. Then I made the spawner send a signal to the main to spawn an enemy at the location of the spawn.

Then I just .connect() the enemy to the HUD at the time it’s instanced.