0 votes

I'm trying to connect my KineticBody2D to it's CollisionShape2D child but whenever I run it, the debugger says:
Attempt to call function 'connect' in base 'null instance' on a null instance.
and I get the error:
Node not found: player
Here is my code:

extends CollisionShape2D

func _ready():
    var player = get_parent()
    $player.connect("phase", self, "_on_Player_phase")

func _on_Player_phase():
    $CollisionShape2D.disabled = true
asked May 9 in Engine by Huday.object (22 points)

1 Answer

+1 vote
Best answer

In your script player is a variable that contains a reference to the parent of the node the script is connected to. To use it in the connect code, you don't want to preface it with the $ sign, as that's just syntactic sugar to reference a node in your scene tree called player, which I assume doesn't exist...

So, really, just drop the $ sign in the connect code.

player.conect(...)
answered May 9 by jgodfrey (5,540 points)
selected May 9 by Huday.object

Thank you so much for the help, this worked.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.