[r178]Calling On Destroy on Layout Change

Bugs will be moved here once resolved.

Post » Thu Aug 21, 2014 9:41 am

Problem Description
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:
- the "On Destroy" to only happen when a destroy action is performed on the object,
- or, to have the choice of the two behaviors with an extra parameter to "On Destroy". Like "On Destroy ignore layout change (yes/no)"

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
UnWantedOnDestroyChangingLayout.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
See capx

Observed Result
The explosion is played on Layout 2

Expected Result
Nothing should happen on Layout 2

Affected Browsers
  • Chrome: (YES)
  • FireFox: (YES)
  • Internet Explorer: (YES)

Operating System and Service Pack
Windows 7 SP1

Construct 2 Version ID
r178
Last edited by Yann on Sun Sep 14, 2014 3:30 pm, edited 1 time in total.
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Thu Aug 21, 2014 11:19 am

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
B
48
S
16
G
9
Posts: 1,098
Reputation: 11,197

Post » Thu Aug 21, 2014 2:57 pm

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.
Scirra Founder
B
397
S
236
G
88
Posts: 24,419
Reputation: 194,542

Post » Thu Aug 21, 2014 4:28 pm

@Ashley
Yeah, I know it's by design, my point was that it shouldn't because you almost never want that to happen.

@spongehammer
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)
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Thu Aug 21, 2014 4:59 pm

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.
Scirra Founder
B
397
S
236
G
88
Posts: 24,419
Reputation: 194,542

Post » Thu Aug 21, 2014 9:15 pm

Hmmm ok, I see, thanks Ash
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Thu Aug 21, 2014 10:49 pm

@Yann

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 :)
B
48
S
16
G
9
Posts: 1,098
Reputation: 11,197


Return to Closed bugs

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests