On Create firing before On Start Layout

0 favourites
  • 6 posts
From the Asset Store
Awardkit
$5 USD
Create custom awards and achievement or use the many templates and create your own.
  • Since Construct 2 still requires the layout to have (as I workaround I can create an extra Loading Layout to handle this but anyway...) at least one instance of every object, when working on small single layout projects I usually start with:

    On start of layout: ChildObj.Destroy()

    I also have an On Create Master Obj : Spawn Child Obj

    From what I can tell though, the On Create is firing *before* On Layout Start, causing an object to be spawned then summarily deleted. Is this order of events intentional?

    Link to .capx file (required!):

    Order of Events Capx

    Steps to reproduce:

    0. Create Layout -> Add ChildObj and ParentObj to Layout

    1. Create ChildObj

    2. Create ParentObj

    3. Add On Create ParentObj : Spawn ChildObj

    4. Add On Start Layout : Destroy ChildObj

    Observed result:

    Both instances of ChildObj are destroyed.

    Expected result:

    Only the existing ChildObj should have been destroyed, then "On Create" should have been run.

    Browsers affected:

    Chrome: yes

    Firefox: yes

    Internet Explorer: yes

    Operating system & service pack:

    Windows 7

    Construct 2 version:

    Release 126

  • I think if you switch the order of the events around, so that the "Start of layout - Destroy ChildObj" happens before "On created - Spawn ChildObj", then it will work.

    If you had lots of ChildObjs on the layout and did a "On start of layout - Destroy ChildObj", it would pick all of them and destroy all of them, which is essentially whats going on if you spawn one in one event, then destroy without specifying which ChildObj to destroy in another event. :P

  • As was demonstrated in the capx example, the start of Layout was already the first event in the event sheet. *Even* if it wasn't the first event linearly in the sheet itself, think about it. On Start of Layout is defined as the condition that occurs when the layout begins, I would think the layout would get initialized before objects were created on said layout.

    The whole point of doing Destroy ChildObj in the "On Start of layout" is to get rid of the troublesome fact that we are required to include one instance of every object on a layout, something which I recall the makers of Construct having stated in the past that they would eventually like to rectify.

  • There was a change to the "firing order" of events in R123 , that could potentially break projects, or mess you up if your used to doing things a certain way...

    unsure if this will help your situation...

    this is the "breaking change" log from that release:

    Breaking change: 'On created' now fires just before 'On start of layout' for every object already on the layout. Previously objects placed in the layout view did not trigger 'On created', but this made it annoying to initialise objects (e.g. you'd have to pin an object both on start of layout and in 'On created'). This will probably break some projects, but it really is more convenient this way round, and hopefully all you need to do is remove the stuff you do in 'On start of layout' that is a duplicate of what happens in 'On created'.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Bingo! That's it! Was not aware of this change. I'll just make it a rule to always have a "StorageLayout" where at least one instance of every object is already initialized.

    Thanks Pixel perfick.

  • Closing, this is by design. Objects have to be created before 'start of layout', otherwise you could not access any objects in 'start of layout' (none would exist), therefore objects are created and fire 'On created' just before 'start of layout'.

    There's nothing wrong with destroying objects on start of layout, even though they were just created. (You can't destroy an object that hasn't been created, anyway.)

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