Spawn multiple objects and make them move towards other objects

I am creating my first game here where I have a stationary base object which spawns units using a timer. I can get them to spawn and move towards another object just fine.

I want them to wander across the map and when they meet the enemy, they will change course and move towards enemy instead.

When reaching the enemy I want them to stop and start fighting, changing the animation and dealing damage.

When the enemy is dead I want my objects to keep moving toward the original object again. When they reach it they should be deleted.

What happens now is they spawn, they move towards object, encounter enemies. Problem is that if there is more than one unit, the others will stop behind the first one and do nothing until the first one defeats the enemy it is fighting.

I think its this code here that stops everyone but I dont know how to fix it since For each doesnt seem to work on groups

For each should work with groups. I suggest you refactor your events so they look like this, and in this order too, and add one extra boolean to the PlayerMelee member objects. The order is important otherwise the actions of one event will trigger the conditions of the following event:

Hey, thanks for the reply

I understand better the flow of code and event order thanks to you. I now got it working for all my units!

I have another question which is menu related, how can I create and select objects in like a main menu scene (select 3 unit types) to use in my level (another scene)?

Could you raise that as a new thread? It’ll be something that more GDevelop users will be interested in, and it’ll be a waste to have it hidden under a spawning objects topic.

Sure! I have done this now.