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

SOLVED: collision_rectangle - Does it work on child objects?

Quick question - I am trying to use collision_rectangle to detect if an object is within a certain area. It works fine on the parent object (the main object). But, I also have variants of that object that are children, it doesn't seem to detect those (though I feel it should).

Am I incorrect in my assumption?

This works with 'obj_torch'
Code:
var torch_in_room = collision_rectangle(0,0,2000,2000,obj_torch,true,true);
if ( torch_in_room == noone ) {
  // Do stuff
}
But, if I have 'obj_torch_invisible' (which is a child of 'obj_torch') it doesn't work.
 

CloseRange

Member
from the docs on parents:
Well, when an object has a parent, it can share code, actions and events with that parent.
you can imagine every bit of code is copied and pasted from one to aother BUT!!!!
what might be your problem is this

if your parent has code in the step event and your child also has code in the step event the step event code will NOT be parented.
if this is the case for you then write this in the child code:
Code:
event_inherited();
event_inherited will inherit any code from the parent object for that specific event
 
from the docs on parents:

you can imagine every bit of code is copied and pasted from one to aother BUT!!!!
what might be your problem is this

if your parent has code in the step event and your child also has code in the step event the step event code will NOT be parented.
if this is the case for you then write this in the child code:
Code:
event_inherited();
event_inherited will inherit any code from the parent object for that specific event
Sure, that makes sense. In this case, though, I have another object checking for these objects. I was hoping that when I do a collision_rectangle and specify an object, it also applies to it's children. That might not be the case, as it seems.
 

CloseRange

Member
i did a quick test to see and no it should be working.
collision_rectangle will check the object specified along with all children object, returning the instance as expected.
The problem has to be somewhere else
 
i did a quick test to see and no it should be working.
collision_rectangle will check the object specified along with all children object, returning the instance as expected.
The problem has to be somewhere else
Ok, thanks for confirming, I will keep at it - something else must be goofed up.
 
I figured out the issue. The collision_rectangle needs the child object to have a sprite assigned to it. My child object was without a sprite, adding that fixed it.
 
Top