GameMaker Depth in GM:S2

So I am trying to learn how to make an RPG, using Game Maker 2 on my Macbook. I'm following HeartBeasts tutorials, and so far everything is working out great. Except with depth of the player object, relative to an enemy object. For some reason I just can not get it to work correctly. The effect I'm going for is extremely simple, which ever object is in front will show in front. I have tried adding depth = -y; to both objects, and I also tried to make a parent object and doing it that way too. As a last resort I followed a more complicated tutorial also using a grid system, but that didn't work either. I just have no idea what I'm doing wrong.

I know this is probably annoyingly simple, but any help would be great!
 

CloseRange

Member
hmm I created a blank project with 2 objects with depth = -y and it works fine.
Did you make sure to put it in the step event? If not then there is probably something else at play.
 
Yup, it's in the step event. I'm extremely confused.

Edit: I also just tried it in a new project, so it has to be my existing code. In my player objects step event contains this

event_inherited();
script_execute(state)

and the only code in the step event for the parent object is as follows

depth = -y;
 
Last edited:
Perhaps it is something in your state scripts. If the parent has the depth setting, and you are inheriting that event into the child (as appears to be the case in the code you showed us), then the only other thing that could be changing the depth in the step event would be whatever state script is being run. What happens if after that script_execute line you put the depth = -y ? Does it change the depth properly? Have you done a show_debug_message(string(depth)) before and after the script_execute, just to see if the depth is changing?
 
I was able to figure out the issue. There was some code in the enemy step event that was messing with the y coordinate, or at least that's what my guess is. Either way it's fixed!
 
Top