[Solved] GDevelop repeatedly deleting the same object

GDevelop appears to not always remove a deleted object when the object is deleted within a repeat block.

If my logic is correct, the following event snip should remove the 4 closest rock objects to the player if at least 4 are within 100 pixels of the player. But it only deletes 1, and I believe this is erroneous.

To confirm, I added an Id variable to the rock object, and used the following to output the number of suitable rock objects, and ids of the rock object being deleted.

GDevelop appears to be repeatedly deleting the same object. This slightly modified version of the previous events screen snip :

resulted in this console output, which suggests GDevelop is removing the same rock object 4 times :


This set of events do remove up to 4 of the nearest rock objects to the player object, but that not quite the same as deleting 4 rock objects if 4 or more of them are closer than 100 pixels :

1 Like

Can you share the dummy project you made? I’ll take a look.

Thanks @Gruk, here’s a link to the .zip of the dummy project that has the behaviour

You probably know multiple ways of achieving what you need, but this might help.

If you want to limit the number of rocks to just 4.

If you want at least 4 rocks to be close by, but want to delete all the rocks that are near the player.

The “for each” is not ideal, but it gets the job done :slight_smile:

Yeah, I’ve got it deleting 4 rock within 100 pixels no problems (it’s in that last screen snip of my first post).

It’s when I add a check that there are at least 4 rocks to delete that the problem occurs. There are more than 4 rocks to delete (the console.log shows that), but it picks the same one 4 times, and deletes it every iteration.

For some reason, the list of candidate objects isn’t being reduced in one scenario, while it is in another.

I can confirm that it has something to do with the repeat and trigger once. (or the trigger once is cancelling the repeat).

I made a quick test trying to use “Pick all objects” in addition to MrMen’s example above:

If I remove Trigger Once, it deletes all of the expected objects (because it’s repeating every frame), with the trigger once, it deletes only 1 object.


You can do it without the repeat in this manner, but then you’re having the event run every frame, which isn’t really preferable.

I don’t think it does.

I’ve done a bit more testing, and found that this deletes the 4 closest objects :

As does this (trigger once added) :

And this (no trigger, console log plain text) :

But this doesn’t (no trigger, console log of object count) :

It almost as if any action or condition that refers to the objects being repeated over prevents the delete from reducing the list of candidate objects.

Hmmm…It could have to do with the Count() expression. It is one of the few expressions I know of that messes with the object list.

The “Number of objects” could be doing something similar.

What if you add another subevent to your “repeat” and add the log message there? put it above your pick/delete event, but keep it as a subevent instead of in the parent event?

Edit: Yes, it’s the count expression.

This works. I don’t like that it requires this extra step, but it works.
Where as this doesn’t, because it has the Count expression in the parent event.:

This feeds back to this thread on the github: Count Object Condition: Unintended behavior for created objects within sub event · Issue #1981 · 4ian/GDevelop · GitHub
The Count Expression/Number of Objects conditions modify the selected object list. I really wish they didn’t (and acted more like just basic true/false conditions similar to the Compare String/Number).

1 Like

Thanks for the GitHub link @Silver-Streak, one of the work arounds mentioned by 4ian is very similar to one I had implemented to get around the issue. But I like your one better :smiley:

1 Like

Hello, Silver!

In your screenshoots is missing the condition by comparing the distance between the two objects (below 100 pixels). I did a test changing the position of “rock” and this worked:

But if i didn’t change the position, but remove the condition that calculates the number of objects still does not work:


Maybe is a problem with the condition “Distance betwen two objects” too?

If I did not understand your post and what I’m saying doesn’t make sense I apologize, but I found curious the result and I thought better share.

As this has been a problem more than once, I suggest these fixes: Count Object Condition: Unintended behavior for created objects within sub event · Issue #1981 · 4ian/GDevelop · GitHub :slight_smile:

1 Like

4ian is coming up with a potential longterm solution (new number of object conditions/count expressions), but for now all you’d have to do is put the “Rock distance to player is below 100 pixels” in the same event I have the count expression in. It’ll narrow the results of the count expression.