Event Order

When considering Events in GameMaker, it should be noted that the exact order that ALL the events are going to occur in each step cannot be clearly stated, simply because it depends on the internal workings of GameMaker and this is subject to change as the software develops or based on the platform where the game is running. However there are certain events that will always run in the same order.

Upon Entering a Room

The first set of events that will always happen the same way are those that occur when a room is first entered. The order that the different events will fire is: 

NOTE You can also set the order in which specific instances are created within The Room Editor itself by moving them up or down the list of the Instance Layer Properties window.

Every Step/Frame

Other than those specific events, events in a game step also always occur in the same order. However, the order of the instances within an event is not always guaranteed, and may vary between different GameMaker versions and target platforms.

As a general rule, you can rely on the order of the events listed below, but not on the order in which the instances in the room execute one event.

For example, you will see below that the "Step" event always executes after the "Begin Step" event, however you cannot guarantee that, for example, Object2 will always execute its Step event after Object1. If you require such an execution order, then making use of a different event is recommended (e.g. putting Object2's Step code in End Step, if you need it to execute after Object1's Step).

So when you have code that relies on specific timing during each step of your game, make use of the events as listed below. To put it simply, first all Begin Step events are executed, then all Step events are executed, after that all End Step events are executed, then all Draw events, etc.

After all Step events are complete, GameMaker executes the Draw events for all instances, in the same game step. Within a particular event (e.g. Draw End), the order in which instances run that event depends on the layer order, e.g. the layer with the highest depth has its instances drawn first, and the layer with the lowest depth is drawn last.

NOTE The layer with the highest depth (which draws first) is displayed at the bottom of the Room Editor's layer list, while the lowest depth layer is at the top (as it is "closer" to the viewer).

Each Draw event draws instances in this order (based on the depth value), and then moves on to the next event, repeating the same instance order (e.g. Draw Begin moving to Draw and then Draw End).

This is the order of the Draw events:

For more detailed information on how these events are related to GameMaker's drawing, see Draw Events.