Actions on recently created objects

I am new to GDevelop, almost finished with a first simple game. It’s an asteroids type of game from top-down perspective. There is one problem I am trying to solve with how the asteroids spawn in.

The asteroids spawn in at random around the outside of the border of the scene area, whenever there are less than 20 asteroids in play. Once the asteroid is created, I need to adjust some stuff on the newly created instance, like push it towards the play area, make it rotate, etc.

This would work fine if I just had one asteroid. But since I have 19 asteroids already in play, the problem is that after creating the single new asteroid the following actions modify all the asteroids instead of just the new one.

I can see there is a “Pick random Object” action that makes the next actions act on only one of the object instances, but instead I would need “Pick most recently created Object” but there doesn’t seem to be such a thing.

Yo estoy creando también mi primer juego, para que cada instancia creada a partir del mismo objeto tenga acciones diferentes uso las variables de instancia, así distingo una de otra, puedes encontrar más información aquí: Object variables [GDevelop wiki]

Hi! I use a small trick that doesn’t needs ID variables.
Just create the object in a position where there will be no one other object of that kind, for example x: -100000, y :-100000
Next select nearest object to that position, apply all the changes you want, and use the last action to put the object wherever you need it. Repeat it for every object you want to create.

1 Like

Thanks! That’s a nice trick that seems it would work in general for this type of thing

Normally any actions that immediately follow a create action will only impact that created object.

However “The number of objects is blah” event condition selects all objects of that type, overriding that behavior.

Another way to do this is to have your count condition as a separate event that sets a scene variable to something like “spawnasteroid =1” and then use that variable plus the trigger once condition for your creation events.

Doing the above will make it so your actions following the object creation in the same event box only applies to that object. Just make sure you set spawnasteroid back to 0 as part of the actions too.

Ah, thanks for the insight into how that “Number of objects” event condition impacts things. I’ll be more careful with its use in future.

No worries, I didn’t know until recently myself. I wouldn’t think that condition would act as object selection, but since it does I wanted to help clear up where the issue was coming in for you.