[SOLVED] Add a light to each new object created

Hi, im trying to create these moving power ups with a ligh object attached to each one of them, but no matter where I put the create light object action, and set their position to always be the same of the object, i keep getting bugs

So what I need is, every time a new power up is created, a light shoud be created with it and folow its movement, and when that instance of the power up is deleted, the light should also be deleted.

If 10 powerups were spawn in the scene, each one of them shoud have a light object attached and moving independently with them

The screenshot is not showing you creating the light object.

As zutty wrote, you’re not creating nor placing the light object. When you create the light object, Use GDevelop Link to associate it to the powerup. It make it easier to keep track of which light belongs to which powerup

1 Like

You need to create the light object right after you create the power up and as mentioned you need to use the object linking event to link the light to the powerup.

Then, you need to use the For each object event to iterate through each instance of the powerup and Take in to account the light object linked to the powerup before you set the position of the light object for each instance of the powerup.
It can be heavy on resources however depends on how many powerup object you have in the scene. In case it is move only in a straight line, instead you may want to add a force to the light object as well to move at the same speed as the powerup.

When you delete a powerup, once again you need to Take in to account the light object linked to the powerup you are about to delete, then delete the light and then delete the powerup.

In case it is too much to take all in, here is an example for you, hope it helps:



That worked REALLY well to me! Thanks a lot! I’ve tried the “link two objects” but I missed the use of “taking into account” I fixed that and it works REALLY well. How can I close this topic?

I think the all powerful moderators do that, though some threads are left open.

You can change the thread title and add the word “[Solved]” to the start. That’ll let others know your question has a solution.