GameMaker: Studio

GameMaker: Studio

View Stats:
Depth used - Parent or Child?
Scenario 1:

obj_A (parent) ...........depth = -200

obj_B (child of A) .......depth = -100

What will the game use as the depth of obj_B?

--------------------------------------------------------------
--------------------------------------------------------------

Scenario 2:

obj_A (parent) ...........depth = -200

obj_B (child of A) .......depth = 0

What will the game use as the depth of obj_B?

--------------------------------------------------------------
--------------------------------------------------------------

I am assuming that an object will always use the depth you specify for it, even if its parent object has a specified depth UNLESS the child object's depth is set to 0, at which point it will inherit the depth of its parent. Is that correct?
Last edited by DirectOrder; Oct 5, 2015 @ 6:17am
< >
Showing 1-6 of 6 comments
I just had to deal with parent / child depths a bit ago in my own program.

So far as I can tell the childs depth setting will always override that of the parent. By default an objects depth starts at 0 so even if you assign it as a child of a parent with a depth higher or lower than 0 it will end up being 0.




In my case with parent / child depth, I had issues when trying to have a child instance draw text to the screen. The parents depth was set to -1 but the childs was still at the default 0 so my text kept getting covered up by other stuff drawn at a -1 depth. I had to set all the children of that object to -1 and even took the extra step of temporarily making the childs depth -100 long enough to draw the text to screen and then setting it back to -1 as this ensured that my text was always on top.
Last edited by BOYCOTT S-T-E-A-M!; Oct 5, 2015 @ 6:37am
Thew Oct 5, 2015 @ 8:24am 
Originally posted by BOYCOTT S-T-E-A-M!:
I just had to deal with parent / child depths a bit ago in my own program.

So far as I can tell the childs depth setting will always override that of the parent. By default an objects depth starts at 0 so even if you assign it as a child of a parent with a depth higher or lower than 0 it will end up being 0.
This is correct. A child object, by default, has it's own depth. It automatically inherits all the events from the parents object unless you override them.

If you want the child object to inherit the parent's depth, you'll need to manually set the depth in the parent's Create Event (or a different event, depending on the situation).
Originally posted by Thew:
If you want the child object to inherit the parent's depth, you'll need to manually set the depth in the parent's Create Event (or a different event, depending on the situation).

That thought hadn't occured to me!

I knew the children inherited the parents events, unless overidden, but I didn't even think of setting the depth in any of the parents events.

This is why I like reading and posting in these forums. I always learn something even if its minor.
DirectOrder Oct 5, 2015 @ 12:47pm 
Excellent information - thank you both for clearing this up for me!
Originally posted by Thew:
If you want the child object to inherit the parent's depth, you'll need to manually set the depth in the parent's Create Event (or a different event, depending on the situation).

Hmm... I just had a situation where I ended up needing to rework my objects depths and it was a pain going through and manually changing them all so I figured I'd do it like you said here so it would inherit it from the parent.

Unforunately, it still doesn't work. I set the depth on the parent both in the depth box and with a line of code in the Creave event, but any children that are created don't inherit the parents depth despite the fact that they are inheriting the parents create event where depth is being set.

Am I doing something wrong here?

UPDATE - The answer is "Yes!" ... I am doing something wrong. I forget the "-" when I set the depth in the creave event of the parent. <coughs> So when its set correctly it works correctly... who'd have thought...
Last edited by BOYCOTT S-T-E-A-M!; Oct 7, 2015 @ 1:14am
TolMera Dec 19, 2016 @ 7:07pm 
var parentDepth = object_get_depth(object_get_parent(object_index));
self.depth = parentDepth;

I ran into the issue myself a few minutes ago, reading here that the child would override the parent, i tried setting the child to a blank value. Which Game Maker set back to zero. (Thanks Game Make!) anyway, I just created the piece of code above and slapped it in the parent objects creator function. On all children I'm running inherit, so this works great for me.

(for anyone looking for this in the future! :) )
Last edited by TolMera; Dec 19, 2016 @ 7:07pm
< >
Showing 1-6 of 6 comments
Per page: 1530 50

Date Posted: Oct 5, 2015 @ 5:42am
Posts: 6