SOLVED Layer/Depth of objects messes up when a room is re-entered.

T

tedd

Guest
Hi! I've been having a problem in GMS2. In my game I have a trigger which the player touches in order to leave to the next room.
This room also has a trigger which allows the player to travel back to the previous room.

There is currently no problems when walking through room to room, it looks normal as it does in the editor.
But when I walk back to the previous rooms and start going back and forth, some objects appear to be shown in the wrong order.
For example:

flower on table.png
flower under table for some reason.png

The first screenshot is the room the first time in it, and the second is when I re-enter.

I've tried setting the depth of the objects to ludicrously low numbers and I've checked for anything that could be changing the object's depth. There doesn't seem to be anything.

Any help is very much appreciated! Thanks :)
 

curato

Member
Are you using the layers built into the room editor or trying to set depth manually? I just create layers in the proper order and when I create objects(or drop them on the level) I make sure put it on a named layer and I have never really seen one incorrectly overlay each other. Now I have see objects on the same layer sometime one or the other is on top if they are in the same spot.
 

NightFrost

Member
you could try debugging this by having those items write their depth on screen. Since you know the layers they're supposed to be on, you can easily tell if something has gone and changed them.
 
T

tedd

Guest
Are you using the layers built into the room editor or trying to set depth manually?
I am currently only using the layers in the room editor, and they are all in the right order. I could try again to manually write the layer though I'm unsure if this would help.
 

samspade

Member
I second @NightFrost's suggestion of running this in the debugger and checking their depth. I can think of only two likely problems:
  • Something is changing their depth/layer
  • There are actual two or more instances, one at the right depth/layer and one created on a different layer
Knowing which is happening would be helpful in figuring out the solution.

It also may be important to know that there are some interesting quirks with persistent instances and layers which may be worth reviewing if you have persistent instances.
 
T

tedd

Guest
I second @NightFrost's suggestion of running this in the debugger and checking their depth.
you could try debugging this by having those items write their depth on screen. Since you know the layers they're supposed to be on, you can easily tell if something has gone and changed them.
Thank you guys so much for your responses! I did a little bit of debugging but couldn't find anything changing the depth - Though I did find a fix.
The problem was to do with the layers. The objects this was affecting were in the same layer and I presume the game doesn't know which order to draw them in / save an order.

Creating more layers with unique depths works perfectly. Silly mistake, thanks for responding regardless.
 

NightFrost

Member
The objects this was affecting were in the same layer and I presume the game doesn't know which order to draw them in / save an order.
Correct, GMS doesn't guarantee draw order for instances on the same layer (or in earlier versions, same depth).
 
Top