Weird Layering Glitch Upon Loading a Save File

Yizzard

Member
Hey so I have a game where in the intro room there are a bunch of office workers sitting behind desks in their cubicles, basically the worker is an object, the desk is an object and then the cubicles are two objects, a blue background object and a green foreground object. When I start a new game and load into that room everything works fine but if I then immediately save and exit the game (using a ini file save/load system) and then load back into that save, I correctly load into that level and everything works correctly except the fact that the layering order is incorrect. The office workers sit in front of their desks for some reason, I have also had this same problem a few other times like when saving outside of buildings sometimes if I close out of the game and load it back up my character will be behind the buildings. Everything still works correctly, but the character is just on the wrong layer for some reason, does anyone have any idea what could cause this? (The office worker sprites are randomized so that's why they're not the same in both pictures)

1605823290095.png1605823212388.png
 

flyinian

Member
Just a guess,

Do the sprites have their own depth in their code? You may need to save that as well. They could be defaulting to the layer that they are at in the room/created at if created through code.
 

Yizzard

Member
The player character does, but everything else is just on my "instances" layer (at depth 100). The player character in it's creation code is just to set its depth to 99 basically though so that should still work too
 

Yizzard

Member
One other thing I just noticed is that the same glitch occurs when I pause the game. I have a pause feature where pressing escape does instance_deactivate_all and then spawns in menu stuff then upon exiting the menu it deletes the menu stuff and instance_activate_all. I have no clue why that would mess up the layering...
 

Yizzard

Member
Just a guess,

Do the sprites have their own depth in their code? You may need to save that as well. They could be defaulting to the layer that they are at in the room/created at if created through code.
Just realized that I probably should've replied to your comment as opposed to just posting a new comment, anyway, for some reason now I can only get it to do the glitch upon pausing and reloading the game no longer causes the glitch... I didn't change anything so I have no clue what could have caused this... I have the debugger checking the depths of the office workers and the cubicles and the desk, and they are all depth 100 except for the cubicle exteriors which in the creation code set the depth to 60. Both before and after the glitch the depths remain the same in the debug window, which doesn't make any sense to me because even if for some reason all of the depth 100 objects were to get mixed up for some reason, surely the depth 60 object should still be in the correct spot? But for some reason it still shows the exterior (the green lines) as behind the interior (the blue box) even though the interior has a depth of 100 and the exterior a depth of 60 after pausing... drawing and layering commands have always been my weak point in game maker...
 

flyinian

Member
Just realized that I probably should've replied to your comment as opposed to just posting a new comment, anyway, for some reason now I can only get it to do the glitch upon pausing and reloading the game no longer causes the glitch... I didn't change anything so I have no clue what could have caused this... I have the debugger checking the depths of the office workers and the cubicles and the desk, and they are all depth 100 except for the cubicle exteriors which in the creation code set the depth to 60. Both before and after the glitch the depths remain the same in the debug window, which doesn't make any sense to me because even if for some reason all of the depth 100 objects were to get mixed up for some reason, surely the depth 60 object should still be in the correct spot? But for some reason it still shows the exterior (the green lines) as behind the interior (the blue box) even though the interior has a depth of 100 and the exterior a depth of 60 after pausing... drawing and layering commands have always been my weak point in game maker...
I'd double check your code and try other methods of setting depth. If this only happens in the intro room and when paused, then it's already isolated. That's half the battle. It's probably just one of those super minor details that was missed and you'll say to yourself, "efheofheroifhoifvnovcnurfch!".

Also, setting depth inside the object may interfere with other depth code elsewhere in game. Just like when you draw text and set its color, v/h align and font in one object but, not in another that is also drawing text and it somehow gets the color, v/h align and font code from the object that does have it.

You can do a quick test by sticking the "depth" variable in the step event(heck, just copy and paste it everywhere in the object events.) in the object drawing the sprite and see if that changes anything.
 
Last edited:

Yizzard

Member
I figured it out, since many of the objects were in the same depth, when the room created them it created them in it's own custom order that I set via instance creation order, but with instance_activate_all it reactivated them based on layer and it's own internal ordering (either alphabetically or the id number of the objects themselves, either way not what I wanted). So in order to fix this, I need to just update the depths after pausing or on every frame since updating depth takes very little processing power especially on a total of like 10 objects in a room.
@flyinian Thanks so much for the help!
 
Last edited:
Top