How to call a special func from another node above

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Serenade
:warning: Old Version Published before Godot 3 was released.

Hi!
I want to get " is_colliding()" from a node above to a CanvasLayer node’s script and get_node(“”).is_colliding() doesnt work…
Im trying to make my player object to add value when its colliding in the CanvasLayer’s script, because i get a little bug when i make part of it in Kinematic2D body’s script…
How can i call “is_colliding()” from kinematic2d to canvaslayer’s script?

What is a “node above”, what “little bug” means?

Remember that is_colliding only works after move in the same physics frame.

eons | 2016-10-30 18:33

Id have showed you if could have puted screenshot in this forum : /
But i kinda did fix the bug…
And thanks about thetip! :slight_smile:

Serenade | 2016-11-01 13:26

:bust_in_silhouette: Reply From: ericdl

To call one layer up, use get_parent() instead of get_node().

:bust_in_silhouette: Reply From: Warlaan

You can access a node’s parent with get_parent(), but I advise against it.
You should always try to write your code so that you only access nodes inside the current scene, otherwise you will create scenes that you can only instantiate if the surrounding scene is built the way you expect it to.

In your case it would probably be a better idea to have the KinematicBody2D node check for collisions and then call a function on its child CanvasLayer node that increases the value.

:bust_in_silhouette: Reply From: avencherus

You can for your own methods, but you can’t for those built-in physics and collision methods. Those are methods that are only coherent inside the physics step, and you only have safe or meaningful access to these kinds of methods from inside of a _fixed_process() or _integrate_forces() call.

For your design you may want to go the other direction, and have the physics events and queries you decide on, to end with call to methods inside your CanvasLayer node script.