Closing as by design: restarting a layout first destroys everything on the layout, and naturally that creates anything you create in "On destroyed". What should happen if you create an object half way through destroying everything because the layout is ending is a question with no clear answer in IMO, and the C2 engine happens to leave them there for the next layout which I think is reasonable. If it went back and destroyed the newly created objects too, it could easily end up hanging, because it could get stuck in an infinite loop as the new objects are destroyed, which creates new objects, which are destroyed, which creates new objects...
Workaround: set a "don't create objects" flag just before restarting the layout, and don't create anything if that flag is set.
Thanks for your constant presence on the forum.
I hope I can change your mind on something, or at least begin a dialogue about it.
I think we're all stuck in this mindset where the only possible way to remove an object is to 'destroy' it. The problem here is that 'destroy' comes with the option to have conditions of "on destroyed" triggers.
This is great, but obviously becomes problematic when going to a new layout. I think destroying all objects on layout change is a mistake, and a new term should be invented within Construct 2. The term should be "remove". Add a "remove" feature to Construct 2 and don't give users the option to have "on remove" triggers.
Remove should be the same as 'destroy' but now it simply removes or deletes the object instead of destroying the object, which can lead to unintended consequences on layout change.
Once a "remove" feature is put into place, then make C2 "remove all objects" upon layout change, instead of "destroy all objects."
I think this is important because errors can occur with the current set-up. For example, if you have a chain of on-destroy triggers, and you do two consecutive layout change with different layer quantities or set-ups, an error will occur and functional gameplay will cease.
1. On BigShip destroy, spawn two ShipHusk.
2. On ShipHusk destroy, spawn Rubble.
Layout 1 has 7 layers, Layout 2 has 1 layer, Layout 3 has 7 layers.
Change from layout 1 to layout 2, Bigship is destroyed, two ShipHusk are created on Layout 2.
Change to layout 3, the two ShipHusk are destroyed and Rubble is created on Layout 3-- but it's not sure what layer to put it on, resulting in an error.
Yes, this can be worked around by adding a variable to all On Destroy triggers. But that means you're asking users to use a workaround for something you won't consider a bug. What is it a workaround for? A lack of a feature?
I hope this post finds you in a good mindset and open to ideas. Thanks for your time!