[SOLVED]Do collision messages propagate from children to parent?

Hello.

Let’s say I have a collection like this :
– # root_object
__|-- ¤ script_component
__|-- # first_child_object
____|-- % collision_object_component
______|-- ■ box_shape
__|-- # second_child_object
____|-- % collision_object_component
______|-- ■ box_shape

In the on_message() function of script_component, if I listen to the “collision_response” message in this script, will the root_object receive the message from the collision_object_component in the child when it collides with another object in the scene (assuming groups and masks are set correctly) ?

Setting up a script component in each child just to send the collision message to their parent seems a little bit too much and I wonder if there is another option.

Maybe I can put a single collision object comprised of the two box shapes in the root object instead, but if the child objects are moved or rescaled, it would require to manually transform the shapes to match the children’s tranforms.

Collision messages (or any messages for that matter) do not propagate up to any parent game objects.

For physics messages specifically there is a new physics.set_listener() function to help with this type of scenario:

So, If I understand correctly, for each level loaded via collection proxies, I would need to set a listener callback function, and resolve every physics interaction I would normally write in a lot of separate objects into this space ?

That’s very useful, thank you.

Yes, the purpose of physics.set_listener() is to have a central manager of collisions instead of multiple scripts. This is especially useful in games with many objects (enemies, bullets, powerups etc) where you’d otherwise need a lot of scripts to deal with physics collisions.

3 Likes