Weird Health Bar issue for Group objects

So I have this Scene group called Enemies

image

I put a health bar on them

image

When the enemy dies, one of them spawns randomly at the same location, and the health bar refills showing the total health of the current enemy. One of them has 10HP and the other 12HP.

image

This is the basic code for their health preview

For spawn and basic damage

When they die

Now for my problem

The health bar works fine most of the time but when the enemy switches from E0002 to E0001 the health bar won’t work again unless I kill E0001 first. Then it doesn’t matter who is the next enemy.

Below link is a gameplay recording, just so that you can understand what I mean
https://imgur.com/a/wKJjSWu

Would really appreciate it if anyone could help, cause I have no idea how to fix this.

What version of GD are you using?

1 Like

I believe the latest version

IDK if it’s a bug or timing but I had a similar problem when I test it. It seems to have 2 objects still picked when it changes the health settings. The old object and the new object. It seems to fail depending on which instances are still picked. Oddly, putting a pick all enemy objects action right after the delete enemy seems to fix it.

1 Like

OMG you are right, it works now, thank you sooo much!!! :open_mouth: :smile:
Today I learned the purpose of the pick-up action. I wonder if this is actually a bug that we should report or just the way that the health bar works.

I plan to add some more enemies so I will return to this post to mark it as solved once I confirm that it works with more enemies.

Weird things can happen when objects are deleted in the same event. I’m still not positive that this isn’t a bug.

Usually, you can delete the object on 1 sub event and then do the rest on another sub event. Not of each other but of the fist event.

Button clicked
----delete object
----create object

I’m wondering if this is because of the group. It’s complex Objects aren’t completely deleted instantly. If there are 2 objects (new and old) , sometimes there are 2 of the same objects, sometimes one of each. The oldest object usually takes precedent when reading values. I’m not sure how it applies to a group. It might still be the oldest object or maybe it’s the order they’re in the group list. IDK.

I’m going to do some testing. A wait action sometimes gives the app time to update things like when objects are deleted but the pick list is still maintained. IDK.

Edit: For my first test, I used 2 objects, an apple and an orange. I used a variable to number them sequentially. I added them to a group list. I added the objects to the scene alternating between apples and oranges. I was a little surprised that the list used in the for each object was sorted by the object and then by the order they were created.

ScreenRecorderProject20

The testing continues.

edit #2: I’m still testing to try to better understand the issue. I do believe it’s because the old object isn’t deleted immediately. So, the old object is sometimes used for the copperRedBar settings. I think that the pick all objects action refreshes the pick list. But I’m still a little unclear about that part.

1 Like

Nice testing man, the ordering surprised me as well. Maybe we should call a Gdevelop developer to solve our question.

That might add some clarity but I think the issue is deleting the object and adding a new object (in the same event or sub event) while the previous object hasn’t been actually deleted. GD sometimes picks the older object instead of the new one. Using separate events also fixed the issue.

or you can use a scene variable

The issue is that conditions and actions both affect the pick list and can cause unexpected things to happen.

1 Like