|Topic was automatically imported from the old Question2Answer platform.
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: https://www.youtube.com/watch?v=5WnumDQyJhg&t=328s
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