M
MadTinkerer
Guest
In my game I have a bunch of instances instantiating instances. With the GMS1, things were pretty straightforward because there was just one instance_create() function. In the new GMS2, we have instance_create_layer() which is even more straightforward because you have the layer built-in variable. But...
So we start with the obj_Interface object, a "God object" that essentially tells everything else what to do. One of the things it does is call the CreateMainMenu() script. The CreateMainMenu script instantiates the Main Menu Buttons including the obj_OpenGame button. When clicked, an instance of obj_OpenGame instantiates the obj_Game object, which is the object that keeps track of everything that needs to be saved when the game is saved.
So, obj_Interface starts in the main room on the default Instances layer, then it calls CreateMainMenu which instantiates the obj_OpenGame button. Now, I meant to use instance_create_layer in CreateMainMenu, but I accidentally used instance_create_depth instead. So as far as I can tell, obj_OpenGame was instantiated with a depth equal to the layer of obj_Interface. This became a problem when I tried to instantiate obj_Game using the layer variable of obj_OpenGame. I'm still not completely sure what GMS2 tried to do, but obj_Game was not instantiating, and it drove me crazy for three days before I realized the problem wasn't even with obj_OpenGame itself, but CreateMainMenu() using the wrong instance_create function.
So I changed the erroneous instance_create_depth()s to instance_create_layer()s and everything now works as intended. I think there needs to be a warning if instance_create_layer is being called from an object that was instantiated with instance_create_depth, because, as far as I can tell, it will just not work, and GMS2 won't give an error message.
So we start with the obj_Interface object, a "God object" that essentially tells everything else what to do. One of the things it does is call the CreateMainMenu() script. The CreateMainMenu script instantiates the Main Menu Buttons including the obj_OpenGame button. When clicked, an instance of obj_OpenGame instantiates the obj_Game object, which is the object that keeps track of everything that needs to be saved when the game is saved.
So, obj_Interface starts in the main room on the default Instances layer, then it calls CreateMainMenu which instantiates the obj_OpenGame button. Now, I meant to use instance_create_layer in CreateMainMenu, but I accidentally used instance_create_depth instead. So as far as I can tell, obj_OpenGame was instantiated with a depth equal to the layer of obj_Interface. This became a problem when I tried to instantiate obj_Game using the layer variable of obj_OpenGame. I'm still not completely sure what GMS2 tried to do, but obj_Game was not instantiating, and it drove me crazy for three days before I realized the problem wasn't even with obj_OpenGame itself, but CreateMainMenu() using the wrong instance_create function.
So I changed the erroneous instance_create_depth()s to instance_create_layer()s and everything now works as intended. I think there needs to be a warning if instance_create_layer is being called from an object that was instantiated with instance_create_depth, because, as far as I can tell, it will just not work, and GMS2 won't give an error message.