[r178]Calling On Destroy on Layout Change

0 favourites
  • 7 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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)

  • 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.

  • Hmmm ok, I see, thanks Ash

  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)