Problem with creating life bar for each enemy in game

i have enemy life bars linking with enemies … the code works great … my problem is that when a new enemy is created the enemy bar is not created while the enemies that are in play at the beginning of the scene have the life bar linked correctly.
Can anyone tell me where am I wrong?
surely there is a problem in the first part of the code where if I remove at the beginning of the scene an infinite number of life bars are created.

How can I take into consideration all enemies in play only once?

you hope to make me understand
sorry for the bad english

thanks in advance to those who can give me a hand

You’ve posted the events for the bit that works. Can you post a screen shot of the events where you create a new enemys object?

player is in collision with box
trigger once
create enemys at position box

the problem is that the enemy life bars are not recreated … only the enemies brought into play at the beginning of the scene are calculated.
I would like every enemy created to be taken into account and linked to a life bar.

removing trigger once from the first event also takes into account the enemies created later but an infinite number of life bars are created

You make the life bar appears when the scene begins, any enemy created “before” the scene begins (put there in the level editor) will have a life bar.

I may suggest an event, checking if there is an enemy without a life bar linked. If it doesn’t has a bar linked, create one and link it to the enemy.

It must look similar to the second repeat, but it must be something like:

Repeat for each instance of enemys:

  • Take into account all enemys not linked to Hpbar (Negate condition)

    + Create object Boss_Hp_txt
    + Link Boss_Hp_txt to enemyes
    + Create Hpbar
    + Link Hpbar to enemyes

This way any new enemy created “after” the beginning of the scene will get the Hp bar and the Hp text.

I hope it helps.

thank you very much your work has worked!


Better practice is to add the HP at the time when the enemy get created. It’ll get actioned once per enemy.

Repeat for each object is inefficient, will get run every single frame, and not the recommended route in this case.

1 Like