Duplicating 0bjects in a layer

H0w d0 I duplicate all 0f the 0bjects in a certain layer int0 an0ther layer mid game using events?

I want t0 c0py all 0f the 0bjects in a certain layer int0 an0ther layer s0 I can make s0me n0n-euclidian levels f0r my game
(s0rry ab0ut the 0s, the letter after n 0n my keyb0ard is br0ken)

Stick them all into an object group. Then in the scene events iterate over each instance of the object group that is on the specific layer and change the layer it’s on.

2 Likes

Thanks! I did that, but instead created an0ther instance 0f the 0bject in the same c00rdinates (because I want t0 keep the 0riginal 0bject in its place)
Is there an easy way t0 link the new 0bject with its 0riginal c0unterpart? This d0esn’t ch00se the c0rrect instance

Firstly, don’t put the beginning of scene inside the repeat. Instead, put the repeat as a subevent of a beginning of scene event. This ensures the repeat is actioned once, rather than having it repeatedly tested throughout the game and is a good programming habit to get into.

The link command will try to link the most recent object (the one created a couple of lines previous) with itself. I’d suggest you add a variable to the group (say named id) and copy the value of the original object to the newly created object.

1 Like

Can you add more details?

You can’t link objects of the same type. You could use a 2nd object as middle link but that might not be practical depending on how many objects you have. You could use matching IDs but I dislike IDs. They can be a pain to maintain but could be your best method. It depends on your needs.

If feasible, could you use the same object with different animations instead of different objects ? Then you could have 2 matching copies using 2 different objects that you could link together. Like objects named Original and Copy. It depends on what the objects represent.

1 Like

I am trying t0 gr0up the c00resp0nding pairs 0f 0bjects s0 that when I m0ve the 0riginal 0bject, the c0py m0ves in the same way 0n the 0ther layer

Hey! If you’re finding that all your duplicates are moving or changing at the same time, the trick is to use Instance Variables. Instead of making a whole new object for every copy, just use one object type and give each instance a different ID or ‘State’ variable. Then, use a ‘For each instance’ event to make sure GDevelop handles them one by one. It saves so much time on the backend!

I think I am just g0ing t0 have t0 create a new 0bject type al0ng with ids, because I am n0t very g00d at using s0 much 0f the same kind 0f 0bject.