The "On Destroy" trigger is called on the object when on layout change.
I can see situations where that would be usefull (like saving some enemies position, though a "On Layout Change" + foreach Enemies would be cleaner)
But in general, you don't really want the "On Destroy" to trigger. Personnally I often use it to trigger special fx like explosion graphics and sounds.
So if you implement an in game pause with an "Exit to Main Menu" button, you'll see and hear the fx when going back to the menu because of this "On Destroy"
I would expect either:
Also, the current behavior is a bit inconsistent since it happens on layout change but not on layout restart, though I'd expect the object to be destroyed and recreated.
Attach a Capx
Description of Capx
Start the preview and just left click to change layout. You'll se the explosion generated by the destruction of the Sprite.
To see the expected result, disable the "Problem" group and enable the "Work Around" group
Steps to Reproduce Bug
The explosion is played on Layout 2
Nothing should happen on Layout 2
Operating System and Service Pack
Windows 7 SP1
Construct 2 Version ID
Looking at this example on my machine.
With Problem enabled and Work around disabled i see the problem observed above.
However with Work Around enabled and problem disabled. I see the the screen with the red sprite and "Text", the explosion spawns straight away without clicking and the "Text " and red sprite remain. The text is at no point renamed to the layout name and even with a left mouse click it doesnt proceed to layout 2.
I understand whats supposed to happen but it just doesnt.
Win 7 SP1 R178
This is by design: all non-global objects are destroyed at the end of the layout, and trigger their 'On destroyed' accordingly, since they are destroyed just like using the "Destroy" action. Use the workaround you've identified if this is not what you want.
Yeah, I know it's by design, my point was that it shouldn't because you almost never want that to happen.
Can't reproduce what you described, be sure events are properly enabled/disabled by group
If you see the explosion on start, it means the particles isn't destroyed, and if left clicking doesn't do anything, check if the left clicking event is properly enabled, and that you're not running with the chrome mobile emulator on. (don't have any more ideas :D)
I really do not want to change how existing features work. Introducing breaking changes causes awkward compatibility issues practically indefinitely, which is too high a price to pay just to make one example work like you think it ought to. There are other possible cases where the existing behavior is useful as well - such as starting an AJAX request or playing a sound when an object is destroyed, and then if we change how it works, that no longer happens, and it is not always obvious how to update existing projects to work like they used to again. Basically users just get upset and blame us for breaking things.
Develop games in your browser. Powerful, performant & highly capable.
Hmmm ok, I see, thanks Ash
All properly enabled/disabled and it does the same thing on IE/Firefox/Chrome
I dont understand why. However as this is not really part of the bug post it doesnt matter.
Still dont understand why though