• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Discussion Persistent layers

What's is the best way to deal with layers and persistent objects in GMS2? I've found when moving a persistent object to a new room it's layer don't follow. My solution in testing has been to find a suitable new layer, moving the object in the room start event.

The objects in question for me are just controller objects and don't do any drawing. Would it be bad practice to just not re-assign the object to a new layer?

I was also thinking of just using instance create depth for any controller objects as these are sort of layer independent. Downside to this being I know create depth is mainly for backwards compatibility and comes with a slight overhead.

Any thoughts?

Update 16/03/19:

It's not a bug the reason it looks like the instances on the "Instances" layer in room0 aren't being carried across to room1 is because they are being recreated at their original depth of 100, and the background in room1 draws over the top of them (as it is also at depth 100). If you set the background depth in room1 to 200 then all instances show up fine.
 
Last edited:
They automatically get assigned to a layer on the same depth as the one they were created on.
Thanks you're right in my testing I'd changed the second rooms default Instance layer to 100 lol my fault, setting it back to 0 sorted it as you said. Thanks!

This may be a fault or just me again but even though I can now see the object has moved into the second room a lookup of the objects layer variable or layer_get_element_layer both return -1 but only after moving to the second room? Both return an id of 0 in the first room as expected.

Also if the adjacent layer depth is not present in the new room wouldn't it be better to automatically create a new layer at the previous depth instead of just nothing?

Could also do with layer debugging being added to the debugger, I'm assuming that's something coming.
 
Last edited:
K

Korbs

Guest
I'm having the exact issue that wipeout described. Persistent object's layers are being set to "-1" once I change rooms. This happens on empty persistent objects. The object's depth remains 350 in both rooms (which is the layer's depth) but the object's layers are being set to -1 once you have left the original room.
 
K

Korbs

Guest
So I made an empty project with 2 rooms (exact same layers), a consistent object(in the first room) that swaps rooms on space press and displays the layer.

It is still setting the layer to -1 and not "automatically assigning to the layer of the same depth":

GIF:
https://gyazo.com/a6334ba67c2ba7074e47ad6181820e8d
 
Last edited by a moderator:
M

MikeVV

Guest
Sorry to bring up a fairly old thread, but I'm seeing the same issue; a persistent object is being set to layer -1 upon room change when a layer with equal depths exists in the next room. Is there any more information? From a comment above, this doesn't seem like intended behavior.

I'm even using a room with a parent room so that layers are inherited.
 
I'm having the same issue.
persistent object, inherited layers, double checked layer depth same in both rooms, change rooms and object gets set to -1. Any update?
 
S

SleepyMolecule

Guest
Turns out, If you inherit the layers in to your new room, and the instance in question is persistent. The persistent instance comes over to the new room, becomes orphaned (layer -1) and you end up with a new duplicate instance from the inherited layer.
Disabling the inherited instance does not help either, the persistent instance that comes over will still be orphaned.
I feel like the best solution is to manage the instance manually, on room start, check to see if the desired layer exists and move the object to that layer.
Instances without a layer seem to function just fine, but I have no idea where they go in terms of execution or draw order (haven't tested).
 

BithSnake

Member
BUMP! Is this issue addressed yet?

I have my main player object set to Persistent (as a lot of you have) and i want to know the depth and layer_name in which the player is in between rooms to troubleshoot a layer-depth issue going between rooms.

After reading this post i made a new object that is created in the Room Creation Event "instance_create_layer(x, y, "TOP_LAYER", oDrawInstanceLayer); and i gave a local variable to the instance you want to check layers on like this:

################################################################
in Draw GUI

var Player = obj_heri;
if(instance_exists(Player))
{
DrawTextColor(10,130,layer_get_depth(Player.layer),c_yellow);
DrawTextColor(10,140,layer_get_name(Player.layer),c_yellow);
}
################################################################

And still i get the orphaned (layer -1)

I thought that this could have solved this issue since you always give the object/instance a new "id"? (correct me if i am wrong).

In the first room everything is A OK, but after that you get the "-1" value. .:/
 

Attachments

gnysek

Member
As this is first result for "layer persistance" in google, I will quote original comment from mantis, which was posted two months later:

The new behaviour is as follows:
- When transitioning from one room to another, we now try to put persistent objects on a layer with the same name as the one they were previously on. If we can't find one with that name then one is created. This means that the layer ID does still change from room to room, but returning to the original room will return the object to its original layer.
More about that can be found in manual too: https://manual.yoyogames.com/GameMa...t/Instances/Instance_Variables/persistent.htm .
 
Top