• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Objects changes layer after room change

zampa

Member
When my player object changes rooms sometimes he changes layer, i was able to solve this by writing layer = layer_get_id("Player"); , but i still do not understand why it does this, i even tried to have all rooms be children of another room, the only difference between room A and room B are the path layers and those layers are "behind" the background layers (they are the layers with the highest depth value)
 

samspade

Member
When my player object changes rooms sometimes he changes layer, i was able to solve this by writing layer = layer_get_id("Player"); , but i still do not understand why it does this, i even tried to have all rooms be children of another room, the only difference between room A and room B are the path layers and those layers are "behind" the background layers (they are the layers with the highest depth value)
Is your player persistent? If so, that means it was created in one room and then moved to another. You'd have to use the debugger to check the variables, but I'm not sure how layers are handled in this case. For example, what if the depth of the Player layer was A in room 1 and B in room 2?

This thread seems to discuss the issue: https://forum.yoyogames.com/index.php?threads/persistent-layers.18769/

It seems like your solution is the best one for the moment. If the layer matters - manually re assign it upon room changes with a persistent object.
 

NightFrost

Member
I haven't had problems with persistent objects switching layers. I make sure every room has layer(s) at same depth as the objects, and I name them the same to avoid any confusion. I have read about room parenting but I feel I have better grasp of the situation when I can see all the layers in the room at the same time. That's just a few extra layers when making a new room so no much extra effort required.
 
Top