Player node not found issue with connecting nodes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Huday.object

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
:bust_in_silhouette: Reply From: jgodfrey

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(...)

Thank you so much for the help, this worked.

Huday.object | 2020-05-09 22:50