For all objects... break;

The for all objects function is quite expensive if you’re trying to find just one specific instance many times in a function. Is it possible to add in a break; condition? For example:

For all objects ship

If ship health = 10 // Do some action
break;

So then as soon as it find the ship with 10 health, the for all objects loop breaks. I have some functions that are using a for each object more than 10 times per function call iterating over many objects and it’s getting rather computationally expensive.

1 Like

I think this’d be a handy feature. I’m surprised it hasn’t had any feedback/activity. I tried looking for similar topics in case this has since been discussed elsewhere, but couldn’t really find anything…

This “break”, isn’t it what happen using a trigger once in the for each loop…?
I’m not sure

This topic is related :

The “for all” call is only if youre selecting all if an object and applying something to those selected objects. In my game i have calls that delete enemies based on health. Its just a “if enemy hp less than 0, then delete enemy.” You dont need a for all to do that. If you wanted to improve performance, have that HP check when the enemy is hit. That way its only checking the enemy that is having its HP checked and not wasting resources on enemies that are not being interacted with.

Hey Folks.

In general, please do not bump 8 year old threads. This was written for a completely different version of the engine (GD4).

Separately, there’s no reason to use a “For each object” event to accomplish the original request.

“Variable “Health” of Ship = 10” > Do some action, along with Trigger once, will do exactly what is asked.

It will find the first applicable instance of the object that matches the criteria, then do the action, then stop until something else hits that criteria, or the variable becomes untrue then true again.

All of the above said, since this is for GDevelop 4, is already accomplishable via the info above, and is an 8 year old thread, I’ll be closing this one out.

If you have a more specific use case you’d like to request, please feel free to make a new thread with specific feature you’re looking for an details on why. Thank you!

1 Like