Room Start Event Execution Order for Persistent Objects in GameMaker: Studio
It’s a well known fact that GameMaker: Studio 1.4 follows this order of events:
- Create Event of each instance
- Instance Creation Code of each instance
- Game Start Event (this will only be run in the very first room of the game)
- Room Creation Code
- Room Start Event of all instances
You can set the order in which specific instances are created within the room editor itself. But what about the Room Start event of persistent instances? Such instances are carried over from room to room. What if we have a room with another, newly created instance, that also executes a Room Start event?
room_01 room_02 obj_persistent -------->obj_persistent obj_new
I made a few tests and it seems that GameMaker, for this specific case, uses Depth. That is: the smaller/lower the depth value of the instance, the sooner it will execute its Room Start event.
I’m talking about instances and not objects because if we change the instance’s depth via code, GameMaker will use that value, not the one defined inside the object editor.
Now jump into your code and have dozens of objects with different conflicting Room Start events (I’m kidding, please don’t)
Thanks a bunch, this is exactly the edge case behavior I needed to investigate. It was super clutch to just be able to set the depth of a controller object to -1000. I appreciate this!