Changing Layout will create objects on the next layout

Bugs will be moved here once resolved.

Post » Mon Jan 05, 2015 6:46 pm

alspal wrote:To me the best way would be to finish running the event sheet (which includes finishing the trigger events, so basically stopping the sheet) THEN destroy all objects and change layout.

It already does that, but destroying objects just before changing layout still triggers 'On destroyed' for those instances (since they're being destroyed by the engine). Triggers still work normally in this case and then you end up creating a new object halfway through the engine's process of switching layout. This is a really awkward time to create a new instance. If the engine then destroyed that instance again, then it risks firing another trigger which creates another instance which the engine then also needs to destroy, creating an infinite loop and hanging (this is what my reply to the other linked bug report was getting at). So it doesn't try, it just destroys everything then switches layout, and if any new objects were created they end up on the next layout.

The workaround should be simple: in the 'go to layout' action set a flag to disable the creation of new objects in 'on destroyed' triggers.

I can't reproduce the "drawing instance on wrong layer" error in the .capx you provided, so I have not attempted to investigate that. Please file a new report with a .capx that reproduces that particular issue if you want me to have a look at that.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Post » Tue Jan 06, 2015 4:33 am

Thanks for the reply!

@ashley I still don't understand why the engine still allows those triggers to be run when they should be stopped though?

I didn't even know what was happening when I experienced this bug, since it's been in every game I've made so far I'd always just expected that you should never change layout if possible because weird stuff happens, thankfully I realized the exact details and I hope other users will be able to stumble upon one of these posts in the future so they don't have to suffer too.
B
147
S
74
G
20
Posts: 1,786
Reputation: 22,527

Post » Tue Jan 06, 2015 6:04 am

@alspal I think that, internally, layouts do not exists like we think they do, so " change layout" is basically just destroying the objects that are not global, destroy the layers, changing the LayoutName value, change the event sheet (already too late), creating the new layers, creating the new objects, apply the on start of layout.

could be wrong though.

still thinkiing that a internal flag verifying that this transition is not happening could be nice to have, but maybe it would be bad regarding general object destruction perfs wise.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Mon May 04, 2015 4:08 am

Finally found this thread to help me fix this issue. I'm going to post this in feature requests, but I think we should have a "Remove object" feature, and also have the layout "remove" objects on layout change rather than "destroy." (Because destroying triggers "On destroy" effects... I think it's obvious that unwanted effects will occur here.) That would have saved me about 4 hours.
B
7
S
1
Posts: 39
Reputation: 511

Post » Mon May 04, 2015 4:17 am

@talqvist I agree, it's still unfathomable to me that this isn't considered a bug. Creating objects on a layout you never told it to create to is considered "working as intended". Image
B
147
S
74
G
20
Posts: 1,786
Reputation: 22,527

Post » Mon May 04, 2015 2:36 pm

alspal wrote:I still don't understand why the engine still allows those triggers to be run when they should be stopped though?




Manual wrote:Go to layout
Go to layout (by name)
Switch to another layout in the project. Note that global variables keep their current value - they are not reset. To reset them use the system action Reset global variables.


FWIW, in the manual it is also not described to work that way. (stopping triggers from firing)

I would stuff those triggers in a group which get disabled before the change layout action, and enabled on start of the next layout.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Post » Tue May 05, 2015 2:24 pm

To play devil's advocate, they aren't described to work in the other way, either. (firing the triggers from the old layout onto the new layout)
If I had to choose the more logical outcome (stopping triggers from firing vs firing the triggers in random locations on a new layout) I'd choose the former.

There's two possible fixes, really.
1) Add a 'remove' feature and set it so changing layouts removes instead of destroys.
or 2) Destroy everything BEFORE the switch to the new layout instead of at the same exact time.
B
7
S
1
Posts: 39
Reputation: 511

Previous

Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 4 guests