• 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.

Question - Code Persistent object invisible after room change

N

noggins

Guest
Not sure if this is a bug or I'm doing something wrong. I have a game with 2 rooms and a persistent player object. When the player object in room0 collides with a room change object the game loads room1 and the camera moves around as if it's following the player at the exact point it would be at, but the player is invisible. If player then collides with room change object and is sent back to room0 the player is visible again. I've done this in GMS:1 and it works, when I do it in GMS2 the exact same way everything works but the player object is invisible in second room.

I also tried creating a persistent non-player object with no code attached, placed it in room0; when room1 loads it's invisible, when room0 is loaded after room change it's visible again. When I attach step code to the non-player persistent object to show an incrementing debug message, it will keep showing the debug message forever whether it's visible in the current room or not. If this same object is then removed from room0 and placed in room1, it won't show the message until room1 is first loaded but then continues to show it after player object leaves room1 so the persistence is technically working, the persistent objects are still in the rooms, they're just invisible in any room other than the room they've been created in.
 

rwkay

GameMaker Staff
GameMaker Dev.
Please file a bug and attach an example project and we will take a look

Russell
 

codemouse

Member
I know this thread has quite a bit of moss on it, but as I was running into a similar problem and found a solution of sorts? Wanted to know if this deserves a new bug report or if I'm missing something.

Steps:
1. Make sure you have a background of some kind
2. Create a player object (persistent)
3. Add it to the Instances layer in the GUI
4. Create a second room with the same "Instances" layer
5. Use code to switch rooms at some point

Result:
1. Player instance still exists
2. Still exists at exact same depth and layer id
3. Not visible - being drawn BELOW the background

Bug:
The player depth is reported as 500, but it's being painted underneath 600, which is the background.

"Fix": object_player.depth -= 1;
This draws the player 1 above the "Instances" layer, at 499, which in theory fixes everything except for the fact that you've now placed it above everything you may create in the Instances layer later?

EDIT3: Reallly....confused now
1. I'm not setting layer depths manually - it's all GMS2
2. In this case, instance layer is reporting depth: 400, tile layer is depth: 500
3. instance_create_depth(x,y,501, objname); will paint on top of the tile layer
4. instance_create_layer(x,y,"Instances", objname); will paint behind the tile layer
 
Last edited:

codemouse

Member
EDITED...(again)

1. A persistent object carries over its previous depth and layer_id
^^ This is really weird, because the layer can have a different depth in the scene, so you could have an object bound to the layer but not obeying the depth level of the layer?

2. Calling layer_add_instance has no effect if called immediately after room_goto
^ It works if you call it later as a button press, but if you call it, say, in the same "if" statement, but after a room_goto, it either silently fails or assigns the depth from the previous room.

That's going to be a hard bug to file a repro project of?

Anyway, the only real solution I can see is to unlock the depth values of each layer in Background Properties and make sure they match between rooms.
 
Last edited:
N

noggins

Guest
Thanks, I added objPlayer.depth-=1; to my room change code after the room_goto call, that works good enough for now.
 
Top