One way that I found to fix this is to add a variable/boolean which is set to false when the layout is being destroyed. Then, you add a condition to all events that have a "on destroyed" and create action saying that this boolean must be true. This makes it so you can't create objects using that method while the layout is switching.