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
in Engine by (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(...)
by (10,856 points)
selected by

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.